我的数据如下:
Id Timestamp Data Group
0 1 2013-08-12 10:29:19.673 40.0 1
1 2 2013-08-13 10:29:20.687 50.0 2
2 3 2013-09-14 10:29:20.687 40.0 1
3 4 2013-10-14 10:29:20.687 30.0 3
4 5 2013-11-15 10:29:20.687 50.0 5
...
我想选择Group
是1
或2
的行。
由于df = df[df['Group'] ==1]
为我提供了Group
是1
的行,所以我认为我可以使用1
为2
或df = df[df['Group'] ==1|df['Group'] ==2]
做行,但返回错误
ValueError Traceback (most recent call last)
<ipython-input-8-5e415899a378> in <module>()
----> 1 df = df[df['Group'] ==1|df['Group'] ==2]
2 df
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in __nonzero__(self)
1553 "The truth value of a {0} is ambiguous. "
1554 "Use a.empty, a.bool(), a.item(), a.any() or a.all().".format(
-> 1555 self.__class__.__name__
1556 )
1557 )
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
这是什么意思,正确的做法是什么?谢谢