Pandas groupby cumsum from last to first

We can create a Serial Number (Index non 0) as: dfm["serial"] = dfm.groupby("token").cumcount()+1

This will create serial as below:

token serial
0 295368217 1
1 294638348 2
2 165168249 3
3 425388540 4
4 284673354 5

But how can I create serial in reverse order? as below:

token serial
0 295368217 5
1 294638348 4
2 165168249 3
3 425388540 2
4 284673354 1

Rows are dynamic

Answer

ty this:

df["serial"] = df["serial"].values[::-1]