Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import pandas as pd def load _ ticket _ data ( ) : file _ paths 'AnnArbor - TicketViolation 2 0 1 7 . xIs',

import pandas as pd
def load_ticket_data():
file_paths
'AnnArbor-TicketViolation2017.xIs',
'AnnArbor-TicketViolation-jan2020.xIs',
'AnnArbor-TicketViolation2019.xIs',
'AnnArbor-TicketViolation2015.xIs',
'AnnArbor-TicketViolation2018.xIs',
'AnnArbor-TicketViolation2016.xIs'
]
df_list =[]
total_rows =0
for file_path in file_paths:
if '2020' in file_path:
df = pd.read_csv(file_path, header=2, skipfooter=1) # Skip 1 footer row for 2020
else:
xls =|pd. ExcelFile(file_path)
sheets_names=xls.sheet_names
df=pd.DataFrame()
for sheet_name in sheet_names:
sheet_df=pd.read_excel(file_path, sheet_name=sheet_name, header=None, skipfooter=0)
if sheet_name in ['Sheet2', 'Sheet3'] and sheet_df.columns[0]=='2080017363': sheet_df = sheet_df.iloc[1:] # Skip the first row for sheet2 and sheet3 of 2015-2019df= pd.concat([df, sheet_df], ignore_index=True)
total_rows += len(df)
if '2020' in file_path:
df.rename(columns={" Fine ": "Fine"}, inplace=True)
else:
df.columns
'Ticket #', 'Badge', 'Issue Date', 'IssueTime', 'Plate', 'State',
'Make', 'Model', 'Violation', 'Description', 'Location', 'Meter',
'Fine', 'Penalty'
]
df_list.append(df)
full_df = pd.concat(df_list, ignore_index=True)
if total_rows != len(full_df):
print("Total rows do not match the number of rows in the concatenated DataFrame.")
return full_df
# Testing the function
df_1_test = load_ticket_data()
print("Total number of rows in all files:", len(df_1_test))
Cannot get correct answer
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Real Time Analytics In Big Data A Comprehensive Guide For Everyone

Authors: Lennox Mark

1st Edition

B0CPTC9LY9, 979-8869045706

More Books

Students also viewed these Databases questions

Question

Identify cultural barriers to communication.

Answered: 1 week ago