Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2 : generate _ descriptors ( ) Write a function called generate _ descriptors ( df ) which takes in the DataFrame you loaded
Question : generatedescriptors
Write a function called generatedescriptorsdf which takes in the DataFrame you loaded from Question and returns a dataframe of all unique ticket descriptions and how frequent they are eg it will tell you how many "HANDICAP" or NO PERMITS UM tickets have been issued for each of the following three time periods: morning am to : am afternoon pm : pm and evening pm : am
Make sure you drop na values of input df
The DataFrame which generatedescriptorsdf returns should have rows and columns.
Index should be labelled as Morning, Afternoon, and Evening.
Column names should be unique values of dfDescription
Need help with question
here is my code:
def generatedescriptorsdf:
import xlrd
import pandas as pd
import numpy as np
import re
# Filter all warnings. If you would like to see the warnings, please comment the two lines below.
import warnings
warnings.filterwarningsignore
# YOUR CODE HERE
# Preprocess the data by dropping NA values
df dfdropna
dfTime pdtodatetimedfTime
dfPeriod pdcutdfTimedthour, bins labelsEvening 'Morning', 'Afternoon', 'Evening' includelowestTrue
dfgrouped dfgroupbyPeriod 'Description'sizeunstackfillna
dfgrouped dfgrouped.locMorning 'Afternoon', 'Evening'
return df
im getting an error.
Important to refer to question :
Question : loadticketdata
First, write the code to create a single DataFrame object in a function called loadticketdata This function should return the full dataframe and take no parameters you can assume the ticket files are in the same directory as your assignment notebook Column labels should be as follows:
Ticket # 'Badge', 'Issue Date 'IssueTime', 'Plate', 'State', 'Make', 'Model', 'Violation', Description', 'Location', 'Meter', Fine 'Penalty'
Here are some hints.
Be sure to scroll through every single sheet to make sure what rows should be dropped.
Make sure to exclude unnecessary footers and headers from the datafile.
Check if your header labels are correct.
here is the answer:
def loadticketdata:
import xlrd
import pandas as pd
import numpy as np
import re
# Filter all warnings. If you would like to see the warnings, please comment the two lines below.
import warnings
warnings.filterwarningsignore
# YOUR CODE HERE
# List of column labels
columnlabels
"Ticket #
"Badge",
"Issue Date
"IssueTime",
"Plate",
"State",
"Make",
"Model",
"Violation",
"Description",
"Location",
"Meter",
"Fine",
"Penalty",
# Prepare a list
# reading all excel files
excelfiles
"name": "AnnArborTicketViolationxls # EXCEL FILE
"sheets":
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
"name": "AnnArborTicketViolationxls # EXCEL FILE
"sheets":
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
"name": "AnnArborTicketViolationxls # EXCEL FILE
"sheets":
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
"name": "AnnArborTicketViolationxls # EXCEL FILE
"sheets":
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
"name": "AnnArborTicketViolationxls # EXCEL FILE
"sheets":
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
name: "Sheet "skiprows": "skipfooter": # SHEET INFO
"name": "AnnArborTicketViolationjanxls # EXCEL FILE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started