Home > Software design >  Remove/Drop Rows if both different column values have same value
Remove/Drop Rows if both different column values have same value

Time:08-11

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?

CodePudding user response:

IIUC:

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

CodePudding user response:

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))]
  • Related