2

I am trying to filter 3 highest values from a column in a data frame without any luck. Can you please help?

I have tried Nlargest etc and it returns the top 3 rows of the highest value

  • 4
    Please, show us what you tried and example data and expected output. – Jerzy Pawlikowski Feb 05 '23 at 15:35
  • 1
    Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Feb 05 '23 at 16:07

1 Answers1

1

Your question is not specific enough, it can be whatever. If you want to get all rows where that match with 3 highest values, you can use:

out = df[df['colA'].isin(df.value_counts('colA').drop_duplicates().head(3))]
Corralien
  • 109,409
  • 8
  • 28
  • 52