Counting bad weather conditions
The weather
DataFrame contains 20 columns that start with 'WT'
, each of which represents a bad weather condition. For example:
WT05
indicates "Hail"WT11
indicates "High or damaging winds"WT17
indicates "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
WT01
throughWT22
fromweather
to a new DataFrame namedWT
. - Calculate the sum of each row in
WT
, and store the results in a newweather
column namedbad_conditions
. - Replace any missing values in
bad_conditions
with a0
. (This has been done for you.) - Create a histogram to visualize
bad_conditions
, and then display the plot.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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