How does missing data in pandas interact with dtypes, alignment, and aggregations (skipna)?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
In pandas, how does missing data interact with dtypes, index alignment, and aggregations (`skipna`)?
Explain what happens to a column's dtype when a value goes missing, where missing values come from when two objects with different indexes are combined, and how reductions treat them by default.
```hint Start from storage
Ask what a NumPy `int64` array is physically able to store, and which pandas dtypes have their own missing-value marker.
```
```hint Edge cases
Work out `s1 + s2` when the two indexes only partly overlap, then ask what an empty or all-missing column sums to and what its mean is.
```
### What a Strong Answer Covers
- What happens to NumPy-backed integer and boolean columns when a value goes missing, and how the nullable extension dtypes avoid it
- Which missing marker each dtype family uses (`NaN`, `NaT`, `pd.NA`)
- How label alignment in arithmetic and combining operations creates missing values, and the tools that control the gaps
- The default `skipna` behavior of reductions, including empty or all-missing input and `count()` versus row counts
- How `groupby` treats rows whose key is missing
### Follow-up Questions
- Within one `groupby` group, `count()` and `size()` return different numbers. What does the gap tell you?
- Why does `if pd.NA:` raise an error while `if np.nan:` runs?
- You merge two DataFrames on a key column that has `NaN` on both sides. What happens, and how does it differ from a SQL join?
- When should you fill missing values before aggregating instead of relying on `skipna`?
Overview: A pandas question on missing data: what happens to a column's dtype when a value goes missing, how index alignment creates gaps in arithmetic, and how reductions and groupby treat missing values by default. It tests working knowledge of NaN, NaT, pd.NA, skipna and nullable dtypes.