Home > Net >  subseting a dataframe excluding top20 and lowest20
subseting a dataframe excluding top20 and lowest20

Time:03-15

I am sampling a dataframe to get 3 new dataframes. The first 2 I use this code:

# Get Top 20 
top20 = df['column'].value_counts().keys()[:20]

# Get Lowest 20
low20 = df['column'].value_counts().keys()[-20:]

What I want:

How can I get the same daframe excluding the top 20 and low 20, I mean getting what's between top 20 and low 20?

CodePudding user response:

Try this:

between = df['column'].value_counts().keys()[20:-20]
  • Related