Project 14: Subscriber Age Corrector
Data Analyst
Builds on these lessons
Current Task
Objective
.loc[] with a boolean condition lets you overwrite only the rows that match — the standard way to correct out-of-range values in place.
Task: replace any age over 120 or under 0 with NaN using .loc, and print the result.
index.py
import pandas as pd
import numpy as np
subscribers = pd.DataFrame({'age': [25, 150, 34, -5]})
subscribers.loc[subscribers['age'] > 120, 'age'] = np.nan
subscribers.loc[subscribers['age'] < 0, 'age'] = np.nan
print(subscribers)
* Hint: Correct characters turn green, incorrect ones turn red.
Live Preview
🖼️
Verify your code to see the preview