In [64]:
import plotly
import plotly.tools as tls
import cufflinks as cf
import pandas as pd
import matplotlib.pyplot as plt
In [65]:
username = 'phillipwong'
api_key = 'jSZgLHfjjQcjQTnsWzhE'
plotly.tools.set_credentials_file(username=username, api_key=api_key)
In [66]:
cols = ['Week Number', 'RequestType', 'Created Year', 'CD']
df = pd.read_csv('311_no_empty_coordinates.csv', usecols = cols)
In [67]:
df['CD'] = pd.to_numeric(df['CD'], errors='coerce')
In [31]:
df['RequestType'].describe()
Out[31]:
In [155]:
x = df.loc[df['RequestType'] == 'Bulky Items']
x = df.loc[df['Created Year'] == 2015]
In [150]:
group = df.groupby(['RequestType','Week Number']).size().unstack()
group
Out[150]:
In [190]:
#NOTE: this encompasses all data points from all years. I need to filter this according to year so I see how it changes within the year and is specific to one week
#Input which week you'd like to see how request types changed for
#Ideally would be able to create a column that analyzes how the last week changed
#as well as find a way to isolate how specific types changed
#but this allows me to see how they all changed from the week before for every week of the year
#group CSV by Request Type and Week Number
group = df.groupby(['RequestType','Week Number']).size().unstack()
#User input to determine what week to see how requests changed
x = df['Week Number'].max()
group['diff'] = group[x] - group [x-1]
#Plotting how each type changed over the week
group['diff'].iplot(kind = 'bar', yTitle='Change in Number of Requests from Previous Week', title='LA 311 Week by Week Comparisons: 2015-2018',
filename='WeeklyComparison')
Out[190]:
In [193]:
df_2015 = df.loc[df['Created Year'] == 2015]
#group CSV by Request Type and Week Number
group_one= df_2015.groupby(['RequestType','Week Number']).size().unstack()
#Determining the latest week in 2016 for which there is data
#then calculating the difference in number of each request type
#between that week and the previous week
x = df_2015['Week Number'].max()
group_one['diff'] = group_one[x] - group_one[x-1]
#Plotting how each type changed over the week
group_one['diff'].iplot(kind = 'bar', yTitle='Change in Number of Requests from Previous Week', title='LA 311 Week by Week Comparisons: 2015',
filename='LA311WeeklyComparison: 2015')
Out[193]:
In [162]:
df_2016 = df.loc[df['Created Year'] == 2016]
#group CSV by Request Type and Week Number
group_two= df_2016.groupby(['RequestType','Week Number']).size().unstack()
#Determining the latest week in 2016 for which there is data
#then calculating the difference in number of each request type
#between that week and the previous week
x = df_2016['Week Number'].max()
group_two['diff'] = group_two[x] - group_two[x-1]
#Plotting how each type changed over the week
group_two['diff'].iplot(kind = 'bar', yTitle='Change in Number of Requests from Previous Week', title='LA 311 Week by Week Comparisons: 2016',
filename='LA311WeeklyComparison2016')
Out[162]:
In [194]:
df_2017 = df.loc[df['Created Year'] == 2017]
#group CSV by Request Type and Week Number
group_three = df_2017.groupby(['RequestType','Week Number']).size().unstack()
#Determining the latest week in 2016 for which there is data
#then calculating the difference in number of each request type
#between that week and the previous week
x = df_2017['Week Number'].max()
group_three['diff'] = group_three[x] - group_three[x-1]
#Plotting how each type changed over the week
group_three['diff'].iplot(kind = 'bar', yTitle='Change in Number of Requests from Previous Week', title='LA 311 Week by Week Comparisons: 2017',
filename='LA311WeeklyComparison2017')
Out[194]:
In [68]:
df_2018 = df.loc[df['Created Year'] == 2018]
#group CSV by Request Type and Week Number
group_four= df_2018.groupby(['RequestType','Week Number']).size().unstack()
#Determining the latest week in 2016 for which there is data
#then calculating the difference in number of each request type
#between that week and the previous week
x = df_2018['Week Number'].max()
group_four['diff'] = group_four[x] - group_four[x-1]
#Plotting how each type changed over the week
group_four['diff'].iplot(kind = 'bar', yTitle='Change in Number of Requests from Previous Week', title='LA 311 Week by Week Comparisons: 2018',
filename='LA311WeeklyComparison2018')
Out[68]:
In [223]:
df_2018_7plus = df.loc[df['CD'] == 1.0]
#group CSV by Request Type and Week Number
cds_7plus= df_2018.groupby(['RequestType','Week Number']).size().unstack()
cds_7plus
Out[223]:
In [ ]: