df.sort_values('value')
tmp = df.groupby('group').size()
rank = tmp.map(range)
rank = [item for sublist in rank for item in sublist]
df['rank'] = rank
Faster way to rank rows in subgroups in pandas dataframe