In [63]:
%matplotlib inline
import metapack as mp
import pandas as pd
import seaborn as sns
from matplotlib import pyplot
mt_pkg = mp.jupyter.open_package()
mt_pkg
Out[63]:
In [2]:
df = mt_pkg.resource('pd_calls').read_csv(low_memory=False)
len(df)
Out[2]:
In [4]:
df.iloc[:5].T
Out[4]:
In [30]:
ct = mt_pkg.resource('call_type').dataframe()
ct
Out[30]:
In [8]:
df['date_time'] = pd.to_datetime(df.date_time)
In [12]:
df.date_time.dt.year.value_counts()
Out[12]:
In [103]:
df['hour'] = df.date_time.dt.hour
df['month'] = df.date_time.dt.month
df['year'] = df.date_time.dt.year
df['dayofweek'] = df.date_time.dt.dayofweek
df['weekofyear'] = df.date_time.dt.weekofyear
df['weekofdata'] = (df.year-df.year.min())*52+df.date_time.dt.weekofyear
df['monthofdata'] = (df.year-df.year.min())*12+df.date_time.dt.month
In [104]:
df.year.describe()
Out[104]:
In [69]:
ht = pd.pivot_table(data=df[df.call_type=='PARTY'],
values='incident_num', index=['hour'],columns=['dayofweek'],
aggfunc='count')
fig, ax = pyplot.subplots(figsize=(10,10))
sns.heatmap(ht, ax=ax)
Out[69]:
In [51]:
ht = pd.pivot_table(data=df[df.call_type=='1150'],
values='incident_num', index=['hour'],columns=['dayofweek'],
aggfunc='count')
sns.heatmap(ht)
Out[51]:
In [50]:
ht = pd.pivot_table(data=df,
values='incident_num', index=['hour'],columns=['month'],
aggfunc='count')
sns.heatmap(ht)
Out[50]:
In [108]:
fig, ax = pyplot.subplots(figsize=(15,8))
top_ct = df.call_type.value_counts().iloc[:10]
top_ct
df_tct = df[df.call_type.isin(list(top_ct.index.values))]
ht = pd.pivot_table(data=df_tct,
values='incident_num', index=['call_type'],columns=['weekofdata'],
aggfunc='count')
ht.T.plot(ax=ax)
#sns.heatmap(ht, robust = True, square=False, ax=ax)
Out[108]:
In [ ]: