I have confirmed this bug exists on the master branch of pandas.
# Your code here
ser = pd.Series([1., 1., 1., 1.])
cat = pd.Categorical(['a', 'b', 'c', np.nan])
print(ser.groupby(cat, dropna=False).sum())
# output:
a 1.0
b 1.0
c 1.0
dtype: float64
Expected Output
a 1.0
b 1.0
c 1.0
NaN 1.0
dtype: float64
Output of pd.show_versions()
Comment From: phofl
Hey,
have you checked #35646? This looks like a duplicate
Comment From: FenderJazz
It looks different from #35646 to me -- is specifically about categoricals, and happens with >1 groupby columns?
Your code here
```ser = pd.Series([1., 1., 1., 1.])
cat = pd.Categorical(['a', 'b', 'c', np.nan]) df = pd.DataFrame({'ser': ser, 'var1': cat, 'var2': cat}) print(df.groupby(['var1', 'var2'], observed=True, dropna=False).sum())
Same but not categorical
noncat = pd.Series(['a', 'b', 'c', np.nan]) df = pd.DataFrame({'ser': ser, 'var1': noncat, 'var2': noncat}) print(df.groupby(['var1', 'var2'], observed=True, dropna=False).sum())
# Output
``` ser
var1 var2
a a 1.0
b b 1.0
c c 1.0
ser
var1 var2
a a 1.0
b b 1.0
c c 1.0
NaN NaN 1.0
Expected output
var1 var2
a a 1.0
b b 1.0
c c 1.0
NaN NaN 1.0
ser
var1 var2
a a 1.0
b b 1.0
c c 1.0
NaN NaN 1.0
Comment From: timstaley
Just a +1 report of hitting this issue, still present on 1.2.0rc0
Comment From: rhshadrach
Thanks for the report! Further investigations and PRs to fix are welcome.