2
我有2個系列。 第一個包含一個索引數爲0..8的數字列表。熊貓選擇未對齊的索引
A = pd.Series([2,3,4,6,5,4,7,6,5], name=['A'], index=[0,1,2,3,4,5,6,7,8])
第二個只包含True值,但該系列的索引是第一個的子集。
B = pd.Series([1, 1, 1, 1, 1], name=['B'], index=[0,2,4,7,8], dtype=bool)
我想用B中的布爾向量來獲得A-值對應的指標,如:
A[B]
[...]
IndexingError: Unalignable boolean Series key provided
不幸的是這引發錯誤。
我需要先對齊它們嗎?
是的,它的工作原理 - 謝謝。 – Ale
@Ale,我稍微修改它:'A [B [B == True] .index.values]'或'A.ix [B [B == True] .index]' – MaxU