开始使用免费开始使用

绘制拦截时长

如果因为某种违章被拦下,您可能会被扣留多长时间?

在本练习中,您将可视化不同违章类型对应的平均拦截时长。这里不使用 violation 列,而是使用信息更详细的 violation_raw 列。

本练习是课程的一部分

使用 pandas 分析警务活动

查看课程

练习说明

  • ri DataFrame 的 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
编辑并运行代码