

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Data Cleaning
incomplete
2: Handling Missing Values
incomplete
3: Handling Duplicates
incomplete
4: Type Normalization
incomplete
5: Converting Types
incomplete
6: Cleaning Dates
incomplete
7: Working With Date Values
incomplete
8: Data Validation
incomplete
9: String Length
incomplete
10: Validation Summary
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Raw data is so often the wrong type. Numbers, dates, and booleans often arrive as strings: "100", "2024-01-15", "Yes".
Type normalization means converting values into the types that make the most sense. Say you want the average shipping cost from an order export, but the values are strings:
df["shipping_cost"] = ["7.25", "12.00", "4.50"]
df["shipping_cost"].mean()
# TypeError
pd.to_numeric() converts strings to numbers:
# Convert a column to numeric
df["shipping_cost"] = pd.to_numeric(df["shipping_cost"], errors="coerce")
# Now you can do math
df["shipping_cost"].mean()
The errors="coerce" option turns unconvertible values into NaN instead of crashing your code.
Before you convert anything, check what you actually have:
# Show types of all columns
print(df.dtypes)
# Check a specific column
print(df["shipping_cost"].dtype)
Complete the split_healthy_unhealthy_devices function. It accepts a DataFrame and a threshold value, then converts the values in the temperature column to numbers and returns two DataFrames: healthy devices below the threshold and unhealthy devices at or above the threshold.