We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Validation Summary

If there isn't a trustworthy fix for invalid rows, sometimes it's best just to remove them:

valid_mask = df["rating"].between(1, 5)
df_clean = df[valid_mask]

That said, silently dropping bad rows can hide real problems. I like to add a validation summary so that the damage remains visible:

invalid_mask = ~df["rating"].between(1, 5)
validation_summary = {
    "total_rows": len(df),
    "invalid_ratings": invalid_mask.sum(),
}

Assignment

Complete the remove_invalid_device_data function. It accepts a DataFrame with temperature and battery_level columns. Return a cleaned DataFrame with only valid records and a validation summary dictionary.