

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
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
Dates are messy because everyone writes them differently. 2024-01-15, 01/15/2024, and Jan 15, 2024 are all the same day, but completely different strings.
The pd.to_datetime() function can convert dates into a single datetime64[ns] type. Pass format="mixed" when the input contains multiple formats. It can also handle invalid dates with the errors="coerce" option, which turns them into NaT ("Not a Time").
# Parse mixed formats
df["date"] = pd.to_datetime(df["date"], format="mixed")
# Coerce invalid values to NaT
df["date"] = pd.to_datetime(df["date"], format="mixed", errors="coerce")
Complete the parse_device_timestamps function. It accepts a DataFrame with a timestamp (string) column, then returns a DataFrame with parsed datetimes and invalid timestamp rows removed.