>>> df.groupby('id').first() valueid 1 first2 first3 first4 second5 first6 first7 fourth如果需要
id作为列:
>>> df.groupby('id').first().reset_index() id value0 1 first1 2 first2 3 first3 4 second4 5 first5 6 first6 7 fourth要获取n条第一条记录,可以使用head():
>>> df.groupby('id').head(2).reset_index(drop=True) id value0 1 first1 1 second2 2 first3 2 second4 3 first5 3 third6 4 second7 4 fifth8 5 first9 6 first10 6 second11 7 fourth12 7 fifth


