df[df.column_x]
我想,为了只筛选列为False的行,可以使用:
df[~df.column_x]
. 我觉得我以前也这样做过,并且把它看作是公认的答案。
但是,这失败了,因为
~df.column_x
将值转换为整数。见下文。
import pandas as pd . # version 0.24.2
a = pd.Series(['a', 'a', 'a', 'a', 'b', 'a', 'b', 'b', 'b', 'b'])
b = pd.Series([True, True, True, True, True, False, False, False, False, False], dtype=bool)
c = pd.DataFrame(data=[a, b]).T
c.columns = ['Classification', 'Boolean']```
print(~c.Boolean)
0 -2
1 -2
2 -2
3 -2
4 -2
5 -1
6 -1
7 -1
8 -1
9 -1
Name: Boolean, dtype: object
print(~b)
0 False
1 False
2 False
3 False
4 False
5 True
6 True
7 True
8 True
9 True
dtype: bool
c[~b]
,但不是
c[~c.Boolean]
我是不是在做梦,梦见这是用来工作的?