BUG: DataFrameGroupBy.nunique fails with categorical, multiple groupings, and as_index=False · Issue #52848 · pandas-dev/pandas (original) (raw)

df = DataFrame({"a1": [0, 0, 1], "a2": [2, 3, 3], "b": [4, 5, 6]})
df = df.astype({"a1": "category", "a2": "category"})
gb = df.groupby(by=["a1", "a2"], as_index=False, observed=False)
gb.nunique()