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
0to'good' - Convert
1through4to'bad' - Convert
5through9to'worse'
Diese Übung ist Teil des Kurses
Analyzing Police Activity with pandas
Anleitung zur Übung
- Count the unique values in the
bad_conditionscolumn and sort the index. (This has been done for you.) - Create a dictionary called
mappingthat maps thebad_conditionsintegers to the specified strings. - Convert the
bad_conditionsintegers to strings using themappingand store the results in a new column calledrating. - Count the unique values in
ratingto verify that the integers were properly converted to strings.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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(____)