1
idx float str+list
1   -0.2  [A,B]
1   -0.1  [A,D]
1    0.2  [B,C]

To know the best result : df.loc[df['float'].idxmax()]['str+list']

How can I have the top 2 idxmax results?

nlargest gives me error

geen21
  • 71
  • 6
  • Does this answer your question? [How to get top 5 values from pandas dataframe?](https://stackoverflow.com/questions/47462690/how-to-get-top-5-values-from-pandas-dataframe) – mozway Sep 30 '21 at 08:11
  • partially but that's not the exact answer – geen21 Sep 30 '21 at 08:38

1 Answers1

1

Use DataFrame.nlargest:

s = df.nlargest(2, 'float')['str+list']
print (s)
2    [B,C]
1    [A,D]
Name: str+list, dtype: object

Or sorting with select top N values:

df.sort_values('float', ascending=False)['str+list'].head(2)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252