1

df

snip,Fbuffmeal_beta,Mbuffmeal_beta
rs11571877,-4.4,-5.9
kgp17983401,63.4,-2.1
kgp17731494,1.2,1.0
kgp2277054,-8.66333,-29.222

How to remove/drop rows only if both Fbuffmeal_beta & Mbuffmeal_beta column values are less than 0.1?

Desired Output:

snip,Fbuffmeal_beta,Mbuffmeal_beta
kgp17983401,63.4,-2.1
kgp17731494,1.2,1.0

I have tried this code:

df.loc[(df['Fbuffmeal_beta'] < 0.1) & (df['Mbuffmeal_beta'] < 0.1)]

but returning rows of which I want to remove

snip,Fbuffmeal_beta,Mbuffmeal_beta
rs11571877,-4.4,-5.9
kgp2277054,-8.66333,-29.222

can anyone help me where I'm going wrong?

paul raj
  • 13
  • 6
  • Is it strictly **less than** or **less than or equal** to 0.1? Just change your loc equalities from `...<0.1 &...` to either `...>0.1 |...` or `...>=0.1 |...`, respectively. – cornifer Aug 11 '22 at 11:23

2 Answers2

1

You can invert mask to >= with | for bitwise OR:

df1 = df.loc[(df['Fbuffmeal_beta'] >= 0.1) | (df['Mbuffmeal_beta'] >= 0.1)]
print (df1)
          snip  Fbuffmeal_beta  Mbuffmeal_beta
1  kgp17983401            63.4            -2.1
2  kgp17731494             1.2             1.0

Your solution is possible use with invert mask by ~:

df.loc[~((df['Fbuffmeal_beta'] < 0.1) & (df['Mbuffmeal_beta'] < 0.1))]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
1

IIUC:

df.loc[~((df['Fbuffmeal_beta'] < 0.1) & (df['Mbuffmeal_beta'] < 0.1))]
Muhammad Hassan
  • 4,079
  • 1
  • 13
  • 27