Python: Pandas - Delete the first row by group

前端 未结 3 922
不知归路
不知归路 2020-12-10 12:27

I have the following large dataframe (df) that looks like this:

    ID     date        PRICE       
1   10001  19920103  14.500    
2   10001  1         


        
3条回答
  •  青春惊慌失措
    2020-12-10 13:11

    Another one line code is df.groupby('ID').apply(lambda group: group.iloc[1:, 1:])

    Out[100]: 
                 date  PRICE
    ID                      
    10001 2  19920106   14.5
          3  19920107   14.5
    10002 5  19920109   14.5
          6  19920110   14.5
    10003 8  19920114   14.5
          9  19920115   15.0
    

提交回复
热议问题