Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个数据框,我想删除 A 列等于蓝色且 B 列等于绿色的所有行。
我虽然下面应该工作,但事实并非如此。
任何人都可以看到问题
df=df.loc[~(df['A']=='blue' & df['B']=='green')]
使用eq而不是==:
eq
==
df.loc[~(df['A'].eq('blue') & df['B'].eq('green'))]
您应该将两个命题分开:
df1=df.loc[~(df['A']=='blue') & ~(df['B']=='green')]
query
注意!=和or作为德摩根定律的结果
!=
or
df.query('A != "blue" or B != "green"')