Pandasdrill

Level 2: Cleaning Exercise 24 of 63 Pro

Parse dates in day/month/year order

A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.

The task

The `when` column holds dates written as day/month/year, such as 03/04/2024 for 3 April 2024. Convert it to datetimes and return the Series.

What this exercise teaches

Left to guess, pandas reads 03/04/2024 as March 4, the US convention, so every one of these dates lands on the wrong day. An explicit format removes the guess, is faster on large columns, and fails loudly when a value does not match instead of silently swapping day and month.

A hint if you get stuck

pd.to_datetime accepts a format string with %d, %m and %Y, or the dayfirst flag.

Try it now, free, no account needed

The first 15 tasks on Pandasdrill are free. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro adds timed mode and the certificate.

Open this exercise

More exercises in Cleaning