Get startedGet started for free

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.

This exercise is part of the course

Analyzing Police Activity with pandas

View Course

Exercise 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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
Edit and Run Code