pandas 定位多个条件 [英] Pandas loc multiple conditions
本文介绍了 pandas 定位多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框,我想删除列A等于蓝色且列B等于绿色的所有行.
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.
任何人都可以看到问题
df=df.loc[~(df['A']=='blue' & df['B']=='green')]
推荐答案
您应将这两个命题分开:
You should separate the two propositions:
df1=df.loc[~(df['A']=='blue') & ~(df['B']=='green')]
这篇关于 pandas 定位多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文