1

My data looks like this:

    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
                     ...

I want to select rows where Group is 1 or 2. Since df = df[df['Group'] ==1] gives me rows where Group is 1, I thought maybe I could do for 1 or 2 using df = df[df['Group'] ==1|df['Group'] ==2] but it returned error

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().

What does this mean and what is the correct way of doing it? Thanks

nilsinelabore
  • 4,143
  • 17
  • 65
  • 122

0 Answers0