[英]pandas filtering by a boolean series
I am having issue where I am trying to filter a dataframe rows where the corresponding entry in a pandas series object is true.我在尝试过滤熊猫系列对象中相应条目为真的数据帧行时遇到问题。
So, looking at the dataset, I have my input dataframe with size:因此,查看数据集,我的输入数据框具有以下大小:
[37697 rows x 12 columns]
And then I have the corresponding filtering series as:然后我有相应的过滤系列:
0 False
1 False
2 False
3 False
4 False
...
37692 False
37693 False
37694 False
37695 False
37696 False
Name: _merge, Length: 37697, dtype: bool
So, they have the same length but when I do something like:因此,它们具有相同的长度,但是当我执行以下操作时:
df[df.columns[_merge]]
I get:我得到:
boolean index did not match indexed array along dimension 0; dimension is 12 but corresponding boolean dimension is 37697
I tried using r.transpose()
but that still gives the same error.我尝试使用r.transpose()
但仍然给出相同的错误。
df.columns
returns a list of columns in your DataFrame. df.columns
返回df.columns
中的列列表。
Then you wrote [_merge]
, so you attempt to access columns using boolean indexing .然后你写了[_merge]
,所以你尝试使用boolean indexing访问列。
And since your column list has different length from the length of _merge , an exception has been raised.并且由于您的列列表的长度与_merge的长度不同,因此引发了异常。
Try boolean indexing , but on rows of your DataFrame:尝试boolean indexing ,但在 DataFrame 的行上:
df[_merge]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.