【问题标题】:Logic operator for boolean indexing with np.nan in Pandas在 Pandas 中使用 np.nan 进行布尔索引的逻辑运算符
【发布时间】:2018-08-14 13:23:14
【问题描述】:
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

系列如何做逻辑或?为什么结果[3] 为真?

在:

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

有人可以帮助解释两次逻辑或之间的区别吗?

【问题讨论】:

    标签: python pandas indexing logical-operators


    【解决方案1】:

    首先,这是两个问题。

    第一个问题:

    您的问题是您将第二个系列的索引设置为从 1 而不是 0(默认值)开始。

    因此,虽然第一个系列的索引为 [0, 1, 2],但第二个系列的索引为 [1, 2, 3]

    第二个问题:

    请在此处参考此答案:https://stackoverflow.com/a/37132854/677022

    【讨论】:

      猜你喜欢
      • 2014-02-20
      • 2014-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      相关资源
      最近更新 更多