to_datetime
What it is
Parses strings to datetime64, with format= for an explicit pattern, errors="coerce" to turn failures into NaT, and utc=True to normalise timezones.
Why it matters
Nothing else in this module works until the column is a real datetime; comparison and sorting on date strings are lexicographic and wrong.
In the real world: Converting order timestamps from two systems (one in IST, one in UTC) into proper dates so daily totals aren't split across the wrong days.
df["ordered_at"] = pd.to_datetime(
df["ordered_at"], format="%Y-%m-%d %H:%M:%S", errors="coerce", utc=True
)
df["ordered_at"].isna().sum() # how many failed to parseRelying on inferred parsing, which is slow on large files and ambiguous between day-first and month-first. 01/02/2024 parses two different ways and neither raises.
Practise it: Keep Only Each User's Latest Row, Monthly Active Users, Pull the Month Out of a Timestamp