Home > database >  I want to print the 3rd highest value along with the 'Id' as the pic
I want to print the 3rd highest value along with the 'Id' as the pic

Time:08-06

From here I want to print the 3rd highest value along with the 'Id'. A help would be appreciated

Most_Calori_Burner.nlargest(3)

series

CodePudding user response:

TRy this,

df.groupby('Id')['Calories'].sum().sort_values(ascending=False).reset_index().iloc[2]
  • Sort your dataframe in descending order
  • Reset index and take 3rd value.
  • Related