Skip to content

Instantly share code, notes, and snippets.

@nikbpetrov
Created March 20, 2026 07:05
Show Gist options
  • Select an option

  • Save nikbpetrov/18ba6817d78d3eadbb12b6d376514f09 to your computer and use it in GitHub Desktop.

Select an option

Save nikbpetrov/18ba6817d78d3eadbb12b6d376514f09 to your computer and use it in GitHub Desktop.
pd reads null as NaN
import pandas as pd
jsonl = '{"id": "q1", "date": "2025-01-01", "value": 10}\n{"id": "q1", "date": "2025-01-05", "value": null}'
dfr = pd.read_json(jsonl, lines=True, dtype={"id": str, "date": str}, convert_dates=False)
dfr["date"] = pd.to_datetime(dfr["date"])
print(f"Jan 5 value: {dfr.iloc[1]['value']!r} (type: {type(dfr.iloc[1]['value']).__name__})")
# Jan 5 value: np.float64(nan) (type: float64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment