Skip to content

Commit 9fc0db2

Browse files
ezebunanduKevin D Smith
authored and
Kevin D Smith
committed
DOC: Fix DataFrame.query contradiction on use of Python keywords as identifiers (pandas-dev#36311)
1 parent c008624 commit 9fc0db2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pandas/core/frame.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -3238,11 +3238,12 @@ def query(self, expr, inplace=False, **kwargs):
32383238
in the environment by prefixing them with an '@' character like
32393239
``@a + b``.
32403240
3241-
You can refer to column names that contain spaces or operators by
3242-
surrounding them in backticks. This way you can also escape
3243-
names that start with a digit, or those that are a Python keyword.
3244-
Basically when it is not valid Python identifier. See notes down
3245-
for more details.
3241+
You can refer to column names that are not valid Python variable names
3242+
by surrounding them in backticks. Thus, column names containing spaces
3243+
or punctuations (besides underscores) or starting with digits must be
3244+
surrounded by backticks. (For example, a column named "Area (cm^2) would
3245+
be referenced as `Area (cm^2)`). Column names which are Python keywords
3246+
(like "list", "for", "import", etc) cannot be used.
32463247
32473248
For example, if one of your columns is called ``a a`` and you want
32483249
to sum it with ``b``, your query should be ```a a` + b``.

0 commit comments

Comments
 (0)