pyt*_*n16 6 python boolean series pandas
我正在两个系列上执行布尔运算.我期待布尔操作自动执行与同一索引相对应的操作.但它只是通过订单来做.这是预期的行为还是有一些不同的做法?谢谢
b
Out[47]:
AEIS False
AAPL True
ACFN False
Name: OldPosition, dtype: bool
a
Out[48]:
AAPL True
ACFN False
AEIS True
dtype: bool
a&b
Out[50]:
AAPL False
ACFN False
AEIS False
dtype: bool
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎是个错误:
In [1]: a = pd.Series([True, False, True], list('bca'))
In [2]: b = pd.Series([False, True, False], list('abc'))
In [3]: a & b
Out[3]:
b False
c False
a False
dtype: bool
Run Code Online (Sandbox Code Playgroud)
解决方法之一是使用相同的索引重新索引:
In [4]: index = a.index | b.index
In [5]: a.reindex(index) & b.reindex(index)
Out[5]:
a False
b True
c False
dtype: bool
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12428 次 |
| 最近记录: |