[英]Remove records from a dataframe based on multiple conditions
I have a dataframe in Python 3 with 4 True/False variables.我在 Python 3 中有一个数据框,有 4 个 True/False 变量。 If all 4 of the variables are False, I want to remove the records from the dataframe.
如果所有 4 个变量都为 False,我想从数据框中删除记录。
I tried the following but it didn't work for me:我尝试了以下操作,但对我不起作用:
df.drop(df.loc[(df['1']==False) & (df['2']==False) & (df['3']==False) & (df['4']==False)])
If do what's inside the df.drop
then I am able to isolate the records that I wish to remove:如果执行
df.drop
那么我可以隔离我希望删除的记录:
df.loc[(df['1']==False) & (df['2']==False) & (df['3']==False) & (df['4']==False)]
I apologize, this is my first time using StackOverflow for help so please let me know if I need to provide more detail.抱歉,这是我第一次使用 StackOverflow 寻求帮助,所以如果我需要提供更多详细信息,请告诉我。
I was able to accomplish what I wanted with the following:我能够通过以下方式完成我想要的:
df.loc[~((df.1==False) & (df.2==False) & (df.3==False) & (df.4==False))]
Sorry for not being more clear.抱歉没有说得更清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.