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 to avg_hr_cycle.

  • Filter the df_activities for the 'Cycling' activity type. Create a copy of the result using copy() and assign the copy to df_cycle.

  • Fill in the missing values for Average Heart Rate (bpm) in df_cycle with int(avg_hr_cycle) using the fillna() method.

  • Count the missing values for all columns in df_run.

Last updated