CommencerCommencer gratuitement

Comparing drug and search rates

As you saw in the last exercise, the rate of drug-related stops increased significantly between 2005 and 2015. You might hypothesize that the rate of vehicle searches was also increasing, which would have led to an increase in drug-related stops even if more drivers were not carrying drugs.

You can test this hypothesis by calculating the annual search rate, and then plotting it against the annual drug rate. If the hypothesis is true, then you'll see both rates increasing over time.

Cet exercice fait partie du cours

Analyzing Police Activity with pandas

Afficher le cours

Instructions

  • Calculate the annual search rate by resampling the search_conducted column, and save the result as annual_search_rate.
  • Concatenate annual_drug_rate and annual_search_rate along the columns axis, and save the result as annual.
  • Create subplots of the drug and search rates from the annual DataFrame.
  • Display the subplots.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Calculate and save the annual search rate
annual_search_rate = ri.search_conducted.____.mean()

# Concatenate 'annual_drug_rate' and 'annual_search_rate'
annual = pd.concat([____], axis=____)

# Create subplots from 'annual'
annual.plot(____)

# Display the subplots
Modifier et exécuter le code