Task 3
Dealing with missing values
As we can see from the last output, there are 214 missing entries for my average heart rate.
We can't go back in time to get those data, but we can fill in the missing values with an average value. This process is called mean imputation. When imputing the mean to fill in missing data, we need to consider that the average heart rate varies for different activities (e.g., walking vs. running). We'll filter the DataFrames by activity type (Type
) and calculate each activity's mean heart rate, then fill in the missing values with those means.
Implement mean imputation for missing values.
Calculate the sample mean for
Average Heart Rate (bpm)
for the 'Cycling' activity type. Assign the result toavg_hr_cycle
.Filter the
df_activities
for the 'Cycling' activity type. Create a copy of the result usingcopy()
and assign the copy todf_cycle
.Fill in the missing values for
Average Heart Rate (bpm)
indf_cycle
withint(avg_hr_cycle)
using thefillna()
method.Count the missing values for all columns in
df_run
.
Helpful links:
fillna()
method documentation
Last updated