Kom igångKom igång gratis

Plotting stop length

If you were stopped for a particular violation, how long might you expect to be detained?

In this exercise, you'll visualize the average length of time drivers are stopped for each type of violation. Rather than using the violation column in this exercise, you'll use violation_raw since it contains more detailed descriptions of the violations.

Den här övningen är en del av kursen

Analyzing Police Activity with pandas

Visa kurs

Övningsinstruktioner

  • For each value in the ri DataFrame's violation_raw column, calculate the mean number of stop_minutes that a driver is detained.
  • Save the resulting Series as a new object, stop_length.
  • Sort stop_length by its values, and then visualize it using a horizontal bar plot.
  • Display the plot.

Interaktiv övning med praktiskt arbete

Testa den här övningen genom att slutföra den här exempelkoden.

# Calculate the mean 'stop_minutes' for each value in 'violation_raw'
print(____)

# Save the resulting Series as 'stop_length'
stop_length = ____

# Sort 'stop_length' by its values and create a horizontal bar plot
stop_length.____

# Display the plot
Redigera och kör kod