Closed Reimarleo closed 2 weeks ago
from pd.query
docs:
You can refer to column names that are not valid Python variable names by surrounding them in backticks.
In this case, 1B
is not a valid python variable name (python variables can't start with digits).
df.eval("A & `1B`")
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The example above results in this error: A +1 B ^ SyntaxError: invalid syntax
Expected Behavior
Prepending an underscore to the column name in both the dataframe and in the expression fixes the problem. Since pandas allows column names to start with a digit, the .eval function should be able to process expressions with those columns.
0 True 1 False 2 False dtype: bool
Installed Versions