How long per weekday?
Pandas has a number of datetime-related attributes within the .dt
accessor. Many of them are ones you've encountered before, like .dt.month
. Others are convenient and save time compared to standard Python, like .dt.day_name()
.
This exercise is part of the course
Working with Dates and Times in Python
Exercise instructions
- Add a new column to
rides
called'Ride start weekday'
, which is the weekday of theStart date
. - Print the median ride duration for each weekday.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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())