The Problem
Real data moment
Real NYC TLC trip records, 3.47 million of them, each with a genuine pickup timestamp. "Show me the trend over time" — a totally ordinary request — needs those timestamps to actually behave like dates, not just look like them.
import pandas as pd
df = pd.read_parquet("yellow_tripdata_2025-01.parquet")
print(df["tpep_pickup_datetime"].dtype)
datetime64[us]
Parquet preserves real types, so this column arrives already correctly parsed. A CSV export of the same data would not be so lucky — worth keeping in mind, since Lesson 00's .info() habit is exactly what would catch this before it becomes a problem.
The gotcha
Reformat three real pickup timestamps as plain M/D/YYYY text — a completely ordinary thing for a CSV export to do — and sort:
sample["pickup_str"] = sample["tpep_pickup_datetime"].dt.strftime("%-m/%-d/%Y %H:%M")
print(sample.sort_values("pickup_str")[["pickup_str"]])
pickup_str
1263151 1/15/2025 00:12
74477 1/2/2025 00:08
1925993 1/22/2025 00:04
January 15th sorted before January 2nd. Nothing crashed — sort_values did exactly what it's supposed to do on a plain string column: compare character by character. "1/15" starts 1, /, 1 — and 1 < 2, so "1/15..." sorts before "1/2...", exactly like comparing words alphabetically. The column looks like a date. To pandas, until told otherwise, it's just text that happens to contain digits and slashes.
sample["pickup_str"] = pd.to_datetime(sample["pickup_str"])
print(sample.sort_values("pickup_str")[["pickup_str"]])
pickup_str
74477 2025-01-02 00:08:00
1263151 2025-01-15 00:12:00
1925993 2025-01-22 00:04:00
pd.to_datetime() converts the same real text into a genuine datetime dtype — and the identical sort_values call now produces the chronologically correct order, because sorting is comparing real points in time instead of comparing strings.
This bug hides especially well because it often doesn't crash
Sorting a string column never raises an error — it always "succeeds," just by the wrong rule. A silently-wrong chronological order can survive for a long time before anyone notices the trend line looks subtly off, which is longer than most other pandas mistakes get to hide.
A dataset's event_date column contains values like "3/5/2025" and "11/2/2025", read from CSV without parse_dates. Sorting by this column ascending, which comes first?
As plain text, string comparison looks at the first character first: "1" (from "11/2/2025") is less than "3" (from "3/5/2025"), so "11/2/2025" sorts first — even though November 2025 comes chronologically after March 2025. This is the exact same lexicographic trap: unparsed date strings sort by character, not by calendar meaning, and nothing about this raises an error to flag it.