开始使用免费开始使用

平均行程时长

在我们的数据集中,W20529 共进行了 291 次出行。平均每次用了多长时间?我们可以使用 Python 内置函数 sum()len() 来完成计算。

根据您上一个编码练习,数据已加载为 onebike_durations。其中每个条目表示自行车离开停靠点的秒数。

本练习是课程的一部分

在 Python 中处理日期和时间

查看课程

练习说明

  • 计算 onebike_durations 中所有行程的 total_elapsed_time
  • 计算 onebike_durationsnumber_of_trips
  • total_elapsed_time 除以 number_of_trips,得到平均行程时长。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# What was the total duration of all trips?
total_elapsed_time = ____(____)

# What was the total number of trips?
number_of_trips = ____(____)
  
# Divide the total duration by the number of trips
print(____ / ____)
编辑并运行代码