How many joyrides?
Suppose you have a theory that some people take long bike rides before putting their bike back in the same dock. Let's call these rides "joyrides".
You only have data on one bike, so while you can't draw any bigger conclusions, it's certainly worth a look.
Are there many joyrides? How long were they in our data set? Use the median instead of the mean, because we know there are some very long trips in our data set that might skew the answer, and the median is less sensitive to outliers.
This exercise is part of the course
Working with Dates and Times in Python
Exercise instructions
- Create a Pandas Series which is
True
whenStart station
andEnd station
are the same, and assign the result tojoyrides
. - Calculate the median duration of all rides.
- Calculate the median duration of
joyrides
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create joyrides
joyrides = (rides[____] == rides[____])
# Total number of joyrides
print("{} rides were joyrides".format(joyrides.sum()))
# Median of all rides
print("The median duration overall was {:.2f} seconds"\
.format(rides['Duration'].____()))
# Median of joyrides
print("The median duration for joyrides was {:.2f} seconds"\
.format(rides[____]['Duration'].____()))