This question already has an answer here:
I have a dataframe and I want to delete all rows where column A is equal to blue and also col B is equal to green.
I though the below should work, but its not the case.
Can anyone see the problem
df=df.loc[~(df['A']=='blue' & df['B']=='green')]
You should separate the two propositions:
df1=df.loc[~(df['A']=='blue') & ~(df['B']=='green')]
use eq
instead of ==
:
df.loc[~(df['A'].eq('blue') & df['B'].eq('green'))]
来源:https://stackoverflow.com/questions/56890859/pandas-loc-multiple-conditions