繪製攔查時長
如果你因特定違規被攔查,可能會被留置多久?
在這個練習中,你將視覺化各種違規類型下,駕駛被攔查的平均時間。這裡不使用 violation 欄位,而改用 violation_raw,因為它包含更詳細的違規描述。
本練習屬於課程
使用 pandas 分析警方執法活動
練習說明
- 對
riDataFrame 的violation_raw欄位中的每個值,計算駕駛被留置的stop_minutes平均數。 - 將得到的 Series 存成新物件
stop_length。 - 依數值排序
stop_length,接著以水平長條圖視覺化。 - 顯示圖表。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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