You are on page 1of 1

import pandas as pd

import numpy as np
import os
variable = pd.read_csv('C:\Data\Traffic_Accidents.csv')
variable.head()
variable['Date'] = pd.to_datetime(variable['Date'],infer_datetime_format=True)
indexedVar=variable.set_index(['Date'])
from datetime import datetime
indexedVar.head(5)

import matplotlib.pylab as plt


%matplotlib inline
from matplotlib.pylab import rcParams
rcParams['figure.figsize']=10, 6
plt.xlabel("Date")
plt.ylabel("No. of Accidents")
plt.plot(indexedVar)

rolmean=indexedVar.rolling(window=12).mean()
rolstd=indexedVar.rolling(window=12).std()
print(rolmean,rolstd)

orig=plt.plot(indexedVar,color='blue',label='Accidents')
mean=plt.plot(rolmean,color='red',label='Rolling Mean')
std=plt.plot(rolstd,color='black',label='Rolling std')
plt.title('Rolling Mean and Standard Deviation')
plt.show(block=False)

You might also like