Analyzing Police Activity with pandas
Kevin Markham
Founder, Data School
apple
date_and_time price volume change
2018-01-08 16:00:00 174.35 20567800 down
... ... ... ...
2018-03-09 16:00:00 179.98 32185200 up
True
if the price went up, and False
otherwiseapple.change.dtype
dtype('O')
.astype()
can't be used in this casemapping = {'up':True, 'down':False}
apple['is_up'] = apple.change.map(mapping)
apple
date_and_time price volume change is_up
2018-01-08 16:00:00 174.35 20567800 down False
... ... ... ... ...
2018-03-09 16:00:00 179.98 32185200 up True
apple.is_up.mean()
0.5
ri.groupby('violation').search_conducted.mean()
violation
Equipment 0.064280
Moving violation 0.057014
Other 0.045362
Registration/plates 0.093438
Seat belt 0.031513
Speeding 0.021560
search_rate = ri.groupby('violation').search_conducted.mean()
search_rate.plot(kind='bar')
plt.show()
search_rate.sort_values()
violation
Speeding 0.021560
Seat belt 0.031513
Other 0.045362
Moving violation 0.057014
Equipment 0.064280
Registration/plates 0.093438
Name: search_conducted, dtype: float64
search_rate.sort_values().plot(kind='bar')
plt.show()
search_rate.sort_values().plot(kind='barh')
plt.show()
Analyzing Police Activity with pandas