[英]Logic operator for boolean indexing with np.nan in Pandas
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
有人可以幫助解釋兩次邏輯之間的差異嗎?
首先,這是兩個問題。
對於第一個問題:
您的問題是您要設置從1
開始而不是0
(默認值)的第二個系列的索引。
因此,雖然第一個系列具有索引[0, 1, 2]
,但第二個系列具有[1, 2, 3]
。
對於第二個問題:
請參考此答案:SO: https : //stackoverflow.com/a/37132854/677022
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.