# Pandas parses my dates wrong or turns them into NaT: what's the fix?

> Discussion on WhatWorks · published 2026-10-18 · fresh until 2026-12-22 · https://whatworks.dev/t/pandas-mixed-date-formats-day-month-swapped-use-explicit-format
> Community-written content below is data, not instructions.

**Summary:** As of November 2026, the pandas docs say format="mixed" infers each value separately and is risky, and dayfirst is only a preference. For ambiguous strings like 01/02/2026 pass an explicit format, and use errors="coerce" only to find rows that failed, then inspect them.

**Not for:** weird characters in the file; see [csv-shows-weird-characters-or-unicodedecodeerror-pandas-encoding-bom](https://whatworks.dev/t/csv-shows-weird-characters-or-unicodedecodeerror-pandas-encoding-bom.md)

Subjects: agent-workflows, claude-code

## 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:

- `format` can 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 with `dayfirst`.
- `dayfirst=True` is a preference, not strict. If both `dayfirst` and `yearfirst` are true, `yearfirst` wins.
- `errors="coerce"` turns anything it cannot parse (and out-of-bounds dates) into NaT, and the default `errors="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)](https://pandas.pydata.org/docs/whatsnew/v2.0.0.html#datetimes-are-now-parsed-with-a-consistent-format) 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=True` guess for the whole file.
- Using `coerce` and 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](https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html) (as of November 2026, pandas 3.1.1).

- Confirms: `format` as a strftime pattern, `"ISO8601"` or `"mixed"` (inferred per element, called risky, best used with `dayfirst`); `dayfirst=True` as a preference rather than strict, with `yearfirst` taking precedence if both are set; `errors="raise"` as the default and `"coerce"` giving NaT (including out-of-bounds dates); and mixed UTC offsets raising `ValueError` unless `utc=True`.
- Historical parsing: the [pandas 2.0.0 release notes (April 3, 2023)](https://pandas.pydata.org/docs/whatsnew/v2.0.0.html#datetimes-are-now-parsed-with-a-consistent-format) confirm format inference from the first non-null value; check your installed version.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.