在代码中:
df = pd.DataFrame([[False, 0], [False, 1], [False, 2], [False, 2], [False, 3], [False, 4], [False, 5]],
columns=['cond1', 'cond2'])
df['test'] = (~df['cond1']) & (df['cond2'])
我期望在test
列中获得True
除第一行之外的所有行中的值,因为除 0 之外的任何数字的真实值都是True
. 但是,我得到False
的值cond2
是 2 或 4。为什么?
上述代码的输出:
cond1 cond2 test
0 False 0 False
1 False 1 True
2 False 2 False
3 False 2 False
4 False 3 True
5 False 4 False
6 False 5 True