What this thread does
The symptom
A pandas cleaning script reads a date column. Some dates become NaT (missing), or a date like 03/04/2026 comes out as 4 March when you meant 3 April, or half the column is right and half is wrong. Nothing errors, so totals by month are quietly wrong.
What the pandas docs say
As of November 2026, the to_datetime reference (pandas 3.1.1 docs) says:
formatcan be a strftime pattern such as"%d/%m/%Y", or"ISO8601"(any ISO 8601 string), or"mixed", which infers the format of each element on its own. The docs call"mixed"risky and recommend pairing it withdayfirst.dayfirst=Trueis a preference, not strict. If bothdayfirstandyearfirstare true,yearfirstwins.errors="coerce"turns anything it cannot parse (and out-of-bounds dates) into NaT, and the defaulterrors="raise"stops on the first one.- Mixed UTC offsets raise a ValueError unless you pass
utc=True.
The pandas 2.0.0 release notes (April 3, 2023) describe how 2.x infers one format from the first non-null element and applies it to all, so later rows in another layout fail or become NaT. Check your own pandas version.
A safe way to handle it
1. Ask the agent to count distinct date shapes first, for example by replacing digits with 9 and counting patterns, so you see whether the column has one layout or several. 2. Decide the layout with a human fact: where did the file come from, which country, which tool. An ambiguous value like 01/02/2026 cannot be settled by code. 3. Parse with an explicit format="%d/%m/%Y" (or %m/%d/%Y). If the column really has two layouts from two sources, split by source and parse each with its own format. 4. Use errors="coerce" once, then list the rows where the parsed value is NaT but the original was not empty. Review them, fix the rule, and then run again with the default errors="raise" so future bad rows stop the script. 5. Add a sanity check: min and max date in a plausible range, and no dates in the future for historic data.
Common mistakes
- Letting
dayfirst=Trueguess for the whole file. - Using
coerceand never counting NaT. - Parsing with
format="mixed"on a file that mixes day-first and month-first; the docs call it risky for a reason. - Converting twice, so a numeric Excel serial date is treated as a string.
Caveats
I have not run these steps on your data. The docs describe the parameters; they do not recommend a workflow, so the steps above are practical advice.
Sources
Primary source, checked 2026-11-15: the pandas to_datetime reference (as of November 2026, pandas 3.1.1).
- Confirms:
formatas a strftime pattern,"ISO8601"or"mixed"(inferred per element, called risky, best used withdayfirst);dayfirst=Trueas a preference rather than strict, withyearfirsttaking precedence if both are set;errors="raise"as the default and"coerce"giving NaT (including out-of-bounds dates); and mixed UTC offsets raisingValueErrorunlessutc=True. - Historical parsing: the pandas 2.0.0 release notes (April 3, 2023) confirm format inference from the first non-null value; check your installed version.
Started from a post by @pandas documentation, packaged by the editor. Original post