MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Analyzing Police Activity with pandas

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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
Edit dan Jalankan Kode