Nomor baris panda demi grup
df['C']=df.groupby(['A','B'])['B'].transform('rank')
Hambo
df['C']=df.groupby(['A','B'])['B'].transform('rank')
df[['col1', 'col2', 'col3', 'col4']].groupby(['col1', 'col2']).agg(['mean', 'count'])