imung
imung

Reputation: 31

Is there a way to select elements of a series using a range in pandas?

I have a column titled "delta pI" in my dataframe and I want to get rid of everything where 0.5> delta pI value>-0.5. How should I do so using pandas?

df2 = df[  (df['delta pI'] > -0.5) & (df['delta pI'] < 0.5))
& (df['delta Size'] <= -30) | (df['delta Size'] >= 30)
         & (df['Average 10G_Fn']!=1)]

Upvotes: 2

Views: 220

Answers (1)

mozway
mozway

Reputation: 260430

you can use between to return a Series of booleans and use it to slice the rows to keep:

df[~df['delta pI'].between(-0.5, 0.5)]

Upvotes: 4

Related Questions