Skip to content

DOC: "list" is not a keyword - .query() #59232

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
wjandrea opened this issue Jul 11, 2024 · 1 comment · Fixed by #59236
Closed

DOC: "list" is not a keyword - .query() #59232

wjandrea opened this issue Jul 11, 2024 · 1 comment · Fixed by #59236
Assignees

Comments

@wjandrea
Copy link
Contributor

Column names which are Python keywords (like “list”, “for”, “import”, etc) cannot be used.

for and import are keywords, but list is not.

I just tried it and it's fine:

>>> df = pd.DataFrame({'list': [0, 1, 2]})
>>> df.query('list == 1')
   list
1     1

While import does fail:

>>> df1 = pd.DataFrame({'import': ['beans', 'corn']})
>>> df1.query('import == "beans"')
    ...
SyntaxError: Python keyword not valid identifier in numexpr query
>>> # working alternative for reference
>>> df1[df1['import'] == 'beans']
  import
0  beans
@ritwizsinha
Copy link
Contributor

take

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

Successfully merging a pull request may close this issue.

2 participants