Part of my project is to plot using Python. I have a large amount of data on Excel sheet (55k rows), it's the number of car accidents in LA. I need to plot the number of accidents (Yearly, Monthly, Weekly and Daily) so the X axis represents the date and the Y axis represents the number of collisions.The data looks like this:
COLLISION_DATE
20010101
20010101
20010101
20010101
20010101
20010101
Each row in the sheet represents 1 collision. I used this code to get the daily plot
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
df = pd.read_csv('rr.csv')
df['COLLISION_DATE']= pd.to_datetime(df['COLLISION_DATE'].astype(str), format='%Y%m%d')
answer = df.groupby('COLLISION_DATE').size().to_frame('Number of Accidents')
answer.plot.line()
plt.show()
For the monthly and weekly I'm using this code
df = pd.read_csv('rr.csv')
df['COLLISION_DATE'] = pd.to_datetime(df['COLLISION_DATE'],format='%Y%m%d')
df['week'], df['month'], df['year'],df['day'] = df['COLLISION_DATE'].dt.week, df['COLLISION_DATE'].dt.month, df['COLLISION_DATE'].dt.year,df['COLLISION_DATE'].dt.day
answer = df.groupby('month').size().to_frame('Number of Accidents')
answer.plot.line()
plt.show()
It is giving me 12 months on the X-axis, what I need is 180 months (2001 to 2015), then I have to save each result on a new Excel sheet.