Analyzing Police Activity with pandas
Kevin Markham
Founder, Data School
ri.search_conducted.value_counts()
False 83229
True 3307
ri.search_type.value_counts(dropna=False)
NaN 83229
Incident to Arrest 1290
Probable Cause 924
Inventory 219
Reasonable Suspicion 214
Protective Frisk 164
Incident to Arrest,Inventory 123
...
.value_counts()
excludes missing values by defaultdropna=False
displays missing valuesri.search_type.value_counts()
Incident to Arrest 1290
Probable Cause 924
Inventory 219
Reasonable Suspicion 214
Protective Frisk 164
Incident to Arrest,Inventory 123
Incident to Arrest,Probable Cause 100
...
ri['inventory'] = ri.search_type.str.contains('Inventory', na=False)
str.contains()
returns True
if string is found, False
if not foundna=False
returns False
when it finds a missing valueri.inventory.dtype
dtype('bool')
True
means inventory was done, False
means it was notri.inventory.sum()
441
ri.inventory.mean()
0.0050961449570121106
searched = ri[ri.search_conducted == True]
searched.inventory.mean()
0.13335349259147264
Analyzing Police Activity with pandas