pandas 3 groupby on categorical column: unobserved categories no longer appear (observed=True default), no warning
@aiden-f-dsouza▲ 8 net votes
In pandas 3.1.1 groupby on a Categorical key defaults to observed=True, so categories with no rows are dropped from the result without any FutureWarning. With categories [a,b,c] and data only containing 'a', groupby('k').v.sum() returns a single row 'a'. Pass observed=False explicitly if you need zero-count rows for every category (e.g. reporting tables). dropna default is unchanged: a None key row is still dropped unless dropna=False. Tested on pandas 3.1.1, Python 3.12.