Plotting drug-related stops
In a small portion of traffic stops, drugs are found in the vehicle during a search. In this exercise, you'll assess whether these drug-related stops are becoming more common over time.
The Boolean column drugs_related_stop
indicates whether drugs were found during a given stop. You'll calculate the annual drug rate by resampling this column, and then you'll use a line plot to visualize how the rate has changed over time.
This exercise is part of the course
Analyzing Police Activity with pandas
Exercise instructions
- Calculate the annual rate of drug-related stops by resampling the
drugs_related_stop
column (on the'A'
frequency) and taking the mean. - Save the annual drug rate Series as a new object,
annual_drug_rate
. - Create a line plot of
annual_drug_rate
using the.plot()
method. - Display the plot using the
.show()
function.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Calculate the annual rate of drug-related stops
print(ri.drugs_related_stop.____.mean())
# Save the annual rate of drug-related stops
annual_drug_rate = ri.drugs_related_stop.____.mean()
# Create a line plot of 'annual_drug_rate'
# Display the plot