Rating the weather conditions
In the previous exercise, you counted the number of bad weather conditions each day. In this exercise, you'll use the counts to create a rating system for the weather.
The counts range from 0 to 9, and should be converted to ratings as follows:
- Convert
0
to'good'
- Convert
1
through4
to'bad'
- Convert
5
through9
to'worse'
This exercise is part of the course
Analyzing Police Activity with pandas
Exercise instructions
- Count the unique values in the
bad_conditions
column and sort the index. (This has been done for you.) - Create a dictionary called
mapping
that maps thebad_conditions
integers to the specified strings. - Convert the
bad_conditions
integers to strings using themapping
and store the results in a new column calledrating
. - Count the unique values in
rating
to verify that the integers were properly converted to strings.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Count the unique values in 'bad_conditions' and sort the index
print(weather.bad_conditions.value_counts().sort_index())
# Create a dictionary that maps integers to strings
mapping = {0:'good', 1:'bad', 2:'bad', ____}
# Convert the 'bad_conditions' integers to strings using the 'mapping'
weather['rating'] = weather.bad_conditions.____
# Count the unique values in 'rating'
print(____)