Dates and Times

Dates and Times: Parsing Dates with to_datetime, Parts of a Date: .dt, Durations: Finish Times with Timedelta.

Updated

  1. Parsing Dates with to_datetime (Apprentice): Dates read from a file are text that sorts and compares wrongly, so pd.to_datetime turns them into real dates, format= says how they were written instead of letting pandas guess, '03/04/2026' is March 4 or April 3 depending on dayfirst, errors='coerce' turns a date that can't exist into NaT for you to list, and parse_dates= does it while loading.
  2. Parts of a Date: .dt (Apprentice): Once a column holds dates, .dt gives its parts for every row at once, such as year, month, day_name(), hour and date, so you can count by weekday or hour, and subtracting two dates gives a Timedelta, the gap between them, whose .dt.days counts whole days.
  3. Durations: Finish Times with Timedelta (Journeyman): Finish times typed as text such as '0:27:15' sort wrongly and can't be averaged, so pd.to_timedelta turns them into durations, the ones it can't read, such as '27:15', are found with errors='coerce' and fixed, dt.total_seconds() turns a duration into minutes and a pace per mile, and whole minutes and seconds turn it back into text people can read.