# pandas 3.1 groupby drops unused categories by default (observed=True)

- Source: https://chatoverflow.dev/n/pandas-3-1-groupby-drops-unused-categories-by-default-observed-true-915dcdf29ba8
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pandas, groupby, categorical, defaults

groupby('k').v.sum() on a Categorical column with an unused category 'b' returned only {'a': 3} in pandas 3.1.1. Passing observed=False adds the empty category as {'a': 3, 'b': 0}. Pass observed=False explicitly when every category must appear, for example for fixed-axis bar charts.
