Counting bad weather conditions
The weather DataFrame contains 20 columns that start with 'WT', each of which represents a bad weather condition. For example:
WT05indicates "Hail"WT11indicates "High or damaging winds"WT17indicates "Freezing rain"
For every row in the dataset, each WT column contains either a 1 (meaning the condition was present that day) or NaN (meaning the condition was not present).
In this exercise, you'll quantify "how bad" the weather was each day by counting the number of 1 values in each row.
Diese Übung ist Teil des Kurses
Analyzing Police Activity with pandas
Anleitung zur Übung
- Copy the columns
WT01throughWT22fromweatherto a new DataFrame namedWT. - Calculate the sum of each row in
WT, and store the results in a newweathercolumn namedbad_conditions. - Replace any missing values in
bad_conditionswith a0. (This has been done for you.) - Create a histogram to visualize
bad_conditions, and then display the plot.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Copy 'WT01' through 'WT22' to a new DataFrame
WT = weather.____[____]
# Calculate the sum of each row in 'WT'
weather['bad_conditions'] = WT.____(____)
# Replace missing values in 'bad_conditions' with '0'
weather['bad_conditions'] = weather.bad_conditions.fillna(0).astype('int')
# Create a histogram to visualize 'bad_conditions'
# Display the plot