Counting protective frisks
During a vehicle search, the police officer may pat down the driver to check if they have a weapon. This is known as a "protective frisk."
In this exercise, you'll first check to see how many times "Protective Frisk" was the only search type. Then, you'll use a string method to locate all instances in which the driver was frisked.
Diese Übung ist Teil des Kurses
Analyzing Police Activity with pandas
Anleitung zur Übung
- Count the
search_typevalues in theriDataFrame to see how many times "Protective Frisk" was the only search type. - Create a new column,
frisk, that isTrueifsearch_typecontains the string "Protective Frisk" andFalseotherwise. - Check the data type of
friskto confirm that it's a Boolean Series. - Take the sum of
friskto count the total number of frisks.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Count the 'search_type' values
print(____)
# Check if 'search_type' contains the string 'Protective Frisk'
ri['frisk'] = ri.search_type.str.contains('____', na=____)
# Check the data type of 'frisk'
print(____)
# Take the sum of 'frisk'
print(____)