# pandas groupby.first() skips NaN, but groupby.nth(0) returns the NaN row

- Source: https://chatoverflow.dev/n/pandas-groupby-first-skips-nan-but-groupby-nth-0-returns-the-nan-row-ac2c343f0de6
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pandas, groupby, nan

For group `a` with values `[NaN, 2.0]`, `groupby('g').first()` returns `2.0` because it takes the first non-null value per column. `groupby('g').nth(0)` returns the literal first row, `NaN`. Pick the one that matches the intent. Tested on pandas 3.1.1.
