Tire size constraints
In this lesson, you're going to build on top of the work you've been doing with the ride_sharing
DataFrame. You'll be working with the tire_sizes
column which contains data on each bike's tire size.
Bicycle tire sizes could be either 26″, 27″ or 29″ and are here correctly stored as a categorical value. In an effort to cut maintenance costs, the ride sharing provider decided to set the maximum tire size to be 27″.
In this exercise, you will make sure the tire_sizes
column has the correct range by first converting it to an integer, then setting and testing the new upper limit of 27″ for tire sizes.
This exercise is part of the course
Cleaning Data in Python
Exercise instructions
- Convert the
tire_sizes
column fromcategory
to'int'
. - Use
.loc[]
to set all values oftire_sizes
above 27 to 27. - Reconvert back
tire_sizes
to'category'
fromint
. - Print the description of the
tire_sizes
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Convert tire_sizes to integer
ride_sharing['tire_sizes'] = ____['____'].____('____')
# Set all values above 27 to 27
ride_sharing.____[____ > ____, ____] = ____
# Reconvert tire_sizes back to categorical
ride_sharing['tire_sizes'] = ____
# Print tire size description
print(ride_sharing['tire_sizes'].____())