pandas - get most recent value of a particular column indexed by another column (get maximum value of a particular column indexed by another column)

前端 未结 6 662
深忆病人
深忆病人 2020-12-01 11:05

I have the following dataframe:

   obj_id   data_date   value
0  4        2011-11-01  59500    
1  2        2011-10-01  35200 
2  4        2010-07-31  24860          


        
6条回答
  •  自闭症患者
    2020-12-01 11:40

    Updating thetainted1's answer since some of the functions have future warnings now as tommy.carstensen pointed out. Here's what worked for me:

    sorted = df.sort_values(by='data_date')
    
    result = sorted.drop_duplicates('obj_id', keep='last')
    

提交回复
热议问题