Pandas中用于布尔索引的逻辑运算符和NaN值。

3
result=pd.Series([True,False,False]) | pd.Series([False,True,True],index=[1,2,3])
result

输出:

0     True
1    False
2     True
3    False
dtype: bool

Series如何进行逻辑或操作?为什么result[3]的值为True?

输入:

print(pd.Series([np.nan]) | pd.Series([True]))
print('----')
print(pd.Series([True]) | pd.Series([np.nan]))

输出:

0    False
dtype: bool
----------
0    True
dtype: bool

有人能帮忙解释一下两个时间逻辑或的区别吗?
1个回答

2
首先,这是两个问题。
对于第一个问题:
你的问题在于你设置了第二个系列的索引从1开始,而不是从0开始(默认值)。
因此,第一个系列的索引为[0, 1, 2],而第二个系列的索引为[1, 2, 3]。
对于第二个问题:
请参考SO中的这个答案:https://dev59.com/0loU5IYBdhLWcg3wxI2A#37132854

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接