def row_number(df, par_list, order_list, asc_list):
df['r'] = 1
df.sort_values(by=par_list + order_list,
ascending=[True]*len(par_list)+asc_list,
inplace=True)
df['r']=df.groupby(par_list)['r'].cumsum()
row_number(df, ['uid'], ['pred_1'], [False])
df[df.r==1]


![[python]dataframe实现row [python]dataframe实现row](http://www.mshxw.com/aiimages/31/321828.png)
