【发布时间】:2013-06-03 14:37:54
【问题描述】:
这样的示例:
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 和 t.shift_two 1 t[t.shift_one > 0 和 t.shift_two
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
假设我们想得到一个包含两个条件的子集,怎么做?非常感谢。
【问题讨论】: