3

このようなサンプル:

In [39]: ts = pd.Series(np.random.randn(20),index=pd.date_range('1/1/2000',periods=20))
In [40]: t = pd.DataFrame(ts,columns=['base'],index=ts.index)
In [42]: t['shift_one'] = t.base - t.base.shift(1)
In [43]: t['shift_two'] = t.shift_one.shift(1)
In [44]: t
Out[44]: 
                base  shift_one  shift_two
2000-01-01 -1.239924        NaN        NaN
2000-01-02  1.116260   2.356184        NaN
2000-01-03  0.401853  -0.714407   2.356184
2000-01-04 -0.823275  -1.225128  -0.714407
2000-01-05 -0.562103   0.261171  -1.225128
2000-01-06  0.347143   0.909246   0.261171
.............
2000-01-20 -0.062557  -0.467466   0.512293

ここで、t[t.shift_one > 0] を使用すると問題なく動作しますが、使用すると: [48]: t[t.shift_one > 0 and t.shift_two < 0] -------- -------------------------------------------------- ----------------- ValueError トレースバック (最近の呼び出しが最後) in () ----> 1 t[t.shift_one > 0 and t.shift_two < 0]

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

2 つの条件の両方を含むサブセットを取得したいとします。どうもありがとう。

4

1 に答える 1