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.
Deze oefening maakt deel uit van de cursus
Cleaning Data in Python
Oefeninstructies
- Convert the
tire_sizescolumn fromcategoryto'int'. - Use
.loc[]to set all values oftire_sizesabove 27 to 27. - Reconvert back
tire_sizesto'category'fromint. - Print the description of the
tire_sizes.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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'].____())