How to query comparing strings pandas

Viewed 2922

I just seccessfully did the following query:

df2.query('Neighborhood == "Not assigned"')

The result was the rows witch the value for the column "Neighborhood" was "Not assigned". (in my case zero)

I'm tryind to do this query now:

df2.query('Postal Code == "M5A"')

But I'm getting invalid syntax.

2 Answers

Try using backticks:

df2.query('`Postal Code` == "M5A"')

Adding

df2.query('`Postal Code` == "M5A"')
Related