In [1]:
import dateutil
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.dates import MonthLocator, WeekdayLocator, DateFormatter
%matplotlib inline
In [2]:
bruns = pd.read_csv('../data/4mo_broken_buses.csv', index_col=0)
bruns.head(10)
Out[2]:
In [3]:
dates = bruns.ServiceDate.drop_duplicates()
dates.head(10)
Out[3]:
In [4]:
dates = dates.apply(lambda x: '2' + x[1:])
dates.index = range(len(dates))
dates.head(10)
Out[4]:
In [5]:
bruns.ServiceDate = bruns.ServiceDate.apply(lambda x: '2' + x[1:])
In [6]:
count = dates.apply(lambda x: len(bruns.ServiceDate[bruns.ServiceDate == x]))
count.name = 'Count'
In [7]:
count[0:10]
Out[7]:
In [8]:
countFrame = pd.concat([dates, count],axis=1)
countFrame[countFrame.Count > 40].head(10)
Out[8]:
In [9]:
countFrame.ServiceDate = pd.to_datetime(countFrame.ServiceDate)
countFrame.sort('ServiceDate', inplace=True)
In [10]:
print len(countFrame.ServiceDate)
print len(countFrame.Count)
In [11]:
fig, ax = plt.subplots()
plt.plot_date(countFrame.ServiceDate,countFrame.Count, '-')
months = MonthLocator(range(1, 13), bymonthday=1, interval=12)
monthsFmt = DateFormatter("%b '%y")
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsFmt)
ax.autoscale_view()
#ax.xaxis.grid(False, 'major')
#ax.xaxis.grid(True, 'minor')
ax.grid(True)
fig.autofmt_xdate()
plt.show()