Skip to content

Query function gives error if column names have front slash #12858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
swetabhpathak opened this issue Apr 11, 2016 · 1 comment
Closed

Query function gives error if column names have front slash #12858

swetabhpathak opened this issue Apr 11, 2016 · 1 comment

Comments

@swetabhpathak
Copy link

import pandas
df = pandas.DataFrame({'ColName / WithFrontSlash': [1, 2]})
df['ColName / WithFrontSlash']

0    1
1    2
Name: ColName / WithFrontSlash, dtype: int64

#this output is what is exptected
df.query('ColName / WithFrontSlash > 1')
pandas.computation.ops.UndefinedVariableError: name 'ColName' is not defined

Pandas version is 0.17.1

@jorisvandenbossche
Copy link
Member

Currently you can only refer to column names in query that have no spaces or other special characters. See #6508 for an enhancement request to make this possible.

For now, if you want to use query, you will have to rename the columns. But most usage of query can also be done in other (possibly less performant) ways; in this case: df[df['ColName / WithFrontSlash'] > 1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants