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 exerciseMore exercises in Cleaning
- Fill missing values in one columnPro
- Drop rows missing a key fieldPro
- Convert text to numbersPro
- Tidy up text with strip and lowerPro
- Search text with str.containsPro
- Pull numbers out of codesPro
- Remove duplicate recordsPro
- Rename columns and replace a placeholderPro
- Dates with to_datetime and dtPro
- Clean messy money textPro
- Split a column into twoPro
- Fill gaps with interpolatePro