简体   繁体   English

子集 pandas dataframe 以获得多个连续列上的相同值

[英]Subsetting pandas dataframe for identical value on several consecutive columns

I have a pandas data frame of the following type;我有以下类型的 pandas 数据框;

id | a | b | c | d | e | g
---------------------------

1  | 0 | 1 | 0 | 1 | 1  | 1

2  | 0 | 0 | 0 | 0 | 1  | 0

3  | 0 | 0 | 0 | 0 | 1  | 1

I want to filter rows which has zero for all columns, a through d .我想过滤所有列为零的行, ad I am aware that this can be achieved by;我知道这可以通过以下方式实现;

data[data['a']==0 & data['b']==0 & data ['c'] ==0 & data ['d'] ==0]

But is there a quicker way using iloc or loc to achieve the same.但是有没有更快的方法使用ilocloc来实现相同的目标。 For example, I tried the following;例如,我尝试了以下方法;

data.iloc[:,[1:4]==0]

But it gave me following error message;但它给了我以下错误信息; ValueError: Can only index by location with a [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array]

Any alternate feedback/advice, which can replace my original solution is appreciated.thanks任何可以替代我原始解决方案的替代反馈/建议表示赞赏。谢谢

Do you mean:你的意思是:

df[df.iloc[:,1:4].eq(0).all(1)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM