每个工作日用时多长?
在 .dt 访问器下,pandas 提供了许多与日期时间相关的属性。很多您已经见过,比如 .dt.month。还有一些更方便的功能,相比标准 Python 能节省时间,例如 .dt.day_name()。
本练习是课程的一部分
在 Python 中处理日期和时间
练习说明
- 在
rides中新增一列'Ride start weekday',其值为Start date的星期几。 - 打印每个星期几的骑行时长中位数。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Add a column for the weekday of the start of the ride
rides['Ride start weekday'] = rides['Start date'].____
# Print the median trip time per weekday
print(rides.____(____)['Duration'].median())