Skip to content

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

Closed
@wjandrea

Description

@wjandrea

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions