5 1 dtype: int64 >>> df.groupby("color", dropna=False).ngroup(ascending=False) 0 1 1 0 2 1 3 2 4 2 5 1 dtype: int64 r