In: Computer Science
I have a CSV file with 6 column
Issue id | action id | Issue category | Issue date | Issue Closed Date | Issue Type |
Please write a code in Python that counts the number of issues in each category and the earliest and latest issue date for each category.
Example of csv
Issue id | action id | Issue category | Issue date | Issue Closed Date | Issue Type |
23 | 1 | Noise Complaint | 7/19/2020 | 7/22/2020 | Client Complaint |
24 | 1 | Cleanliness Complaint | 7/19/2020 | 7/23/2020 | Sanitation |
25 | 2 | Site Inspection | 7/20/2020 | 7/20/2020 | Patrol |
26 | 2 | Noise Complaint | 7/19/2020 | 7/23/2020 | Client Complaint |
SAMPLE CSV -
CODE -
import pandas as pd
import datetime
data = pd.read_csv('issue.csv')
data1 = data.groupby('Issue category')
data['Issue date'] = data['Issue date'].apply(lambda v:
datetime.datetime.strptime(v, '%m/%d/%Y'))
print("\nIssue Category \t\tNumber of issues")
print(data['Issue category'].value_counts().to_string())
print("\nEarliest Issue Date: \n")
print(data1['Issue date'].min().to_string())
print("\nLatest Issue Date: \n")
print(data1['Issue date'].max().to_string())
SCREENSHOT -