-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
updating df.query and df.eval docstrings. resolves #16283 #58749
updating df.query and df.eval docstrings. resolves #16283 #58749
Conversation
pandas/core/frame.py
Outdated
You can refer to column names that are not valid Python variable names | ||
by surrounding them in backticks. Thus, column names containing spaces | ||
or punctuations (besides underscores) or starting with digits must be | ||
surrounded by backticks. (For example, a column named "Area (cm^2)" would | ||
be referenced as ```Area (cm^2)```). Column names which are Python keywords | ||
(like "list", "for", "import", etc) cannot be used. | ||
|
||
For example, if one of your columns is called ``a a`` and you want | ||
to sum it with ``b``, your query should be ```a a` + b``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you demonstrate this in the Example
section instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added one example in the Example section. Note that above wording is coming from query
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove all this explanation now that it's explained in the examples section
pandas/core/frame.py
Outdated
2 3 6 9 | ||
3 4 4 8 | ||
4 5 2 7 | ||
A B C C C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These headers don't look correct anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked and it looks correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at the examples here you can see 5 column labels for 4 columns: https://pandas.pydata.org/preview/pandas-dev/pandas/58749/docs/reference/api/pandas.DataFrame.eval.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial example dataframe contains 3 columns: A
, B
and C C
. The eval method will add a fourth column named C
in the resulting dataframe for this example.
Repr of the dataframe does not make the separation of columns obvious when columns contains spaces. It is like there is 3 columns C
when you actually have C C
and C
.
To make the example cristal clear I may change C C
by C&C
and update the examples to add columns with names differents than C
.
Do you want me to update also query
examples as C C
is actually coming from there ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the example cristal clear I may change C C by C&C and update the examples to add columns with names differents than C.
Ah yes that would be great. Sorry I didn't backtrack to see the context of the original columns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall I update query
as well ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please
/preview |
Website preview of this PR available at: https://pandas.pydata.org/preview/pandas-dev/pandas/58749/ |
Thanks @mutricyl |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.This is a docstring improvement suggested in #16283 issue discussion.
df.eval
anddf.query
are updated for consistency and adding exemples with@
usage for local variables