1

I have a df of car miles per gallon data, which are int (as far as I can tell).

Using Pandas, I'm filtering with df.loc[(df['Horsepower'] >90)] which is giving me the results I expect - cars with >90 horsepower. But when I try adding a second filter, I get the below error.

>> df.loc[(df['Horsepower'] >90)] & (df['Weight']< 4500)

TypeError: unsupported operand type(s) for &: 'float' and 'bool'

Is it a syntax issue or am i missing something bigger??

1 Answer 1

5

You have got typo in your code. The brancket ] has to be at the end of the filter:

df.loc[(df['Horsepower'] >90) & (df['Weight']< 4500)]
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.