I have an pandas data frame that looks like:
df = DataFrame({\'id\':[\'a132\',\'a132\',\'b5789\',\'b5789\',\'c1112\',\'c1112\'], \'value\':[0,0,0,0,0,0,]})
Categoricals provide a reasonably easy way to define an arbitrary ordering
In [35]: df['id'] = df['id'].astype('category')
In [39]: df['id'] = (df['id'].cat.reorder_categories(
sorted(df['id'].cat.categories, key = lambda x: int(x[1:]), reverse=True)))
In [40]: df.groupby('id').sum()
Out[40]:
value
id
b5789 0
c1112 0
a132 0