0

I got the following DataFrame:

System             R    System_num
0    CO           0.8           1
1    CO           0.9           1
2    CO           1.0           1
3    CO           1.2           1
4    CO           1.4           1
5    CO           0.8           2
6    CO           0.9           2
7    CO           1.0           2
8    CO           1.2           2
9    CO           1.4           2
10   CO           0.8           3

I would like to return the index of the line for which R = 1.4 and System_num = 2. I've tried by:

df.ix[df.System_num == 2 & df.R == 1.4].index 

Though the error message is returning:

print df.ix[df.System_num == 2 & df.R == 1.4].index

     File "/apps/anaconda/lib/python2.7/site-packages/pandas/core/ops.py", line 834, in wrapper
        na_op(self.values, other),
      File "/apps/anaconda/lib/python2.7/site-packages/pandas/core/ops.py", line 805, in na_op
        x.dtype, type(y).__name__))
    TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]

What am I doing wrong?

2
  • 2
    df.ix[(df.System_num == 2) & (df.R == 1.4)].index you need parenthesis around the comparison also see here. Commented Jan 19, 2017 at 15:05
  • 1
    .ix is finally being deprecated!!! Commented Jan 19, 2017 at 15:33

1 Answer 1

2

You should use parentheses with the & operator. Check out pandas documentation for indexing data. It says:

Another common operation is the use of boolean vectors to filter the data. The operators are: | for or, & for and, and ~ for not. These must be grouped by using parentheses.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.