This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| speedbins = np.linspace(0,185,50) | |
| speeddf2['speedbinned'] = pd.cut(speeddf2['SPEED'], speedbins) | |
| speedbinsviol = speeddf2['speedbinned'].value_counts().sort_index() | |
| speeddf2['new_column'] = speeddf2['LINK_POINTS'].apply(lambda x: x[0:18]) | |
| speeddf3 = pd.DataFrame(speeddf2['new_column'].str.split(',',1).tolist(),columns=['Lat','Long']) | |
| speeddf2['Lat'] = speeddf3['Lat'] | |
| speeddf2['Long'] = speeddf3['Long'] | |
| speeddf4 = speeddf2.loc[speeddf2['SPEED']>65] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| speeddf = pd.read_csv('DOT_Traffic_Speeds_NBE.csv', index_col=False, header=0) | |
| speeddf2 = speeddf.dropna() | |
| print(speeddf2.head(3)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| df2['SpeedFlag'] = np.where(df2['Violation Description'].str.contains("speed", case=False, na=False), 1, 0) | |
| df2['SpeedFlag'] = df2['SpeedFlag'].astype(bool) | |
| speedingviol = df2[df2['SpeedFlag']==1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| agebins = np.linspace(15,90,26) | |
| df2['agebinned'] = pd.cut(df2['Age at Violation'], agebins) | |
| violagebins = df2['agebinned'].value_counts().sort_index() | |
| fig, ax = plt.subplots() | |
| plt.rcParams["figure.figsize"] = (14,10) | |
| violagebins.plot(ax=ax,kind='bar') | |
| plt.xlabel('Age group') | |
| plt.ylabel('Number of violations') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| violage = df2['Age at Violation'].value_counts().sort_index() | |
| fig, ax = plt.subplots() | |
| violage.plot(ax=ax,kind='bar') | |
| plt.rcParams["figure.figsize"] = (14,10) | |
| ticklabels = ['']*len(violage.index) | |
| # Every 4th ticklable shows the month and day | |
| ticklabels[::4] = [item for item in violage.index[::4]] | |
| ax.xaxis.set_major_formatter(ticker.FixedFormatter(ticklabels)) | |
| plt.xlabel('Age at violation') | |
| plt.ylabel('Number of violations') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| violday = df2['Violation Day of Week'].value_counts() | |
| fig, ax = plt.subplots() | |
| violday.plot(ax=ax,kind='bar') | |
| plt.xlabel('Day of week') | |
| plt.ylabel('Number of violations') | |
| plt.show(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| violmonth = df2['Violation Month'].value_counts().sort_index() | |
| fig, ax = plt.subplots() | |
| violmonth.plot(ax=ax,kind='bar') | |
| x1 = [0,1,2,3,4,5,6,7,8,9,10,11] | |
| squad = ['January','February','March','April','May','June','July','August','September','October','November','December'] | |
| matplotlib.rcParams.update({'font.size': 22}) | |
| plt.rcParams["figure.figsize"] = (10,10) | |
| ax.set_xticks(x1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import matplotlib | |
| import matplotlib.ticker as ticker | |
| from matplotlib.cm import plasma | |
| pd.options.mode.chained_assignment = None | |
| df = pd.read_csv('Traffic_Tickets_Issued__Four_Year_Window.csv', index_col=False, header=0) | |
| df2 = df.dropna() # we ignore rows with incomplete data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This is a test gist. |
NewerOlder