LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Analyzing Police Activity with pandas

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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
Code bearbeiten und ausführen