drop unused categories using groupby on categorical variable in pandas

Since version 0.23 you can specify observed=True in the groupby call to achieve the desired behavior.

Leave a Comment