In [2]:
import datetime
import pandas as pd

import matplotlib.pyplot as plt
%matplotlib inline  

import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()

data = pd.read_csv('/home/alex/openjc/github/hackathon/2016-3-19/JCMC_EMS_Data/JCMC_EMS_Data.csv')
data = data[data['Trip Date'] != 'Date']
data['Pick Up Zip'] = data['Pick Up Zip'].apply(lambda x : x if len(x) >= 5 else '0' + x)
data['Trip Date'] = pd.to_datetime(data['Trip Date'])

data.to_csv('./new_data.csv', index=False)
/usr/local/lib/python2.7/dist-packages/pandas/computation/expressions.py:21: UserWarning: The installed version of numexpr 1.4.2 is not supported in pandas and will be not be used
The minimum supported version is 2.1

  "version is 2.1\n".format(ver=ver), UserWarning)
In [3]:
plot_data = []
titles = []

def plot_func(sub_df):
    if sub_df.shape[0] <= 1000:
        return
    
    zip_code = sub_df['Pick Up Zip'].iloc[0]
    result = sub_df['Chief Complaint'].value_counts()
    
    trace1 = go.Bar(
      x=result.index,
      y=result.values,
      name=zip_code
    )
    
    plot_data.append(trace1)
    titles.append(zip_code)

    
data.groupby('Pick Up Zip').apply(func=plot_func)

layout = go.Layout(
      title=titles
)

iplot(go.Figure(data=plot_data, layout=layout), show_link=False)
In [126]:
import numpy as np

done = False

def plot_func(df):
    global done
    if done:
        return
    
    if df.shape[0] <= 1000:
        return
    
    zip_code = df['Pick Up Zip'].iloc[0]
    df.index = df['Trip Date']
    
    
    result = df.groupby('Chief Complaint').resample('1M', how='count')
    
    
    print result
    
    done = True
In [123]:
titles = []
plot_data = []

data.index = data['Trip Date']
result = data.groupby('Chief Complaint').resample('1M', how='count')

for complaint,df in result.groupby(level=0):
    
    title = complaint

    if df.Disposition.max() < 100:
        continue
        
    heyo = result.loc[complaint]
    
    trace = go.Scatter(
      x = heyo.index,
      y = heyo.Disposition,
      name = title
    )   
    
    plot_data.append(trace)
    

iplot(go.Figure(data=plot_data), show_link=False)
In [125]:
titles = []
plot_data = []

data.index = data['Trip Date']
result = data.groupby('Chief Complaint').resample('1M', how='count')

for complaint,df in result.groupby(level=0):
    
    title = complaint

    if df.Disposition.max() < 100:
        continue
        
    heyo = result.loc[complaint]
    
    trace = go.Histogram(x=heyo.Disposition,name=title)
    plot_data.append(trace)
    

iplot(go.Figure(data=plot_data), show_link=False)
In [ ]: