-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the DataFrame.stack docstring #20430
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
DOC: update the DataFrame.stack docstring #20430
Conversation
- Make description and summary clearer. - Fix doctests
Reviewed by Marco.
Separate creation of data with examples.
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.
Great work. Added some comments about formatting, and some that in my opinion should make the examples better.
pandas/core/frame.py
Outdated
----- | ||
The function is named by analogy with a stack of books | ||
(levels) being re-organised from a horizontal position (column | ||
levels) to a vertical position (index levels). | ||
|
||
Examples |
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.
Examples section should go at the end, after Returns and See Also.
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.
Fixed in 99734ac
pandas/core/frame.py
Outdated
onto column axis. | ||
DataFrame.pivot: reshape dataframe from long format to wide | ||
format. | ||
DataFrame.pivot_table: create a spreadsheet-style pivot table |
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.
It should be a space between the colon, and the description should start with a capital letter.
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.
Fixed in 652f7b2
pandas/core/frame.py
Outdated
b 1 | ||
two a 2 | ||
b 3 | ||
dtype: int64 |
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.
It's just a personal opinion, but I think defining all the data first with descriptive names make it a bit more complex to understand.
We could have separate sections for each case, with a title in bold (surrounding the text with double stars, followed by the data creation, using simply df
in all the cases.
Also, in this case I think it would make the example easier to understand using more real-world examples. As a
, b
... don't have a meaning, it'd a bit harder to understand what's going on.
A minor thing, when creating the data, I think it makes more sense that each row is defined as a tuple, than as a list.
For example:
**Single level**
>>> df = pd.DataFrame([(8, 12), (22, 35)],
... index=['cat', 'dog'],
... columns=['weight', 'max_speed'])
>>> df
>>> df.stack()
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.
👍 split the examples in several sections in 15902ed
Codecov Report
@@ Coverage Diff @@
## master #20430 +/- ##
==========================================
+ Coverage 91.8% 91.85% +0.04%
==========================================
Files 152 152
Lines 49215 49231 +16
==========================================
+ Hits 45181 45220 +39
+ Misses 4034 4011 -23
Continue to review full report at Codecov.
|
More clear than lumping all the definitions into a single section at the start.
Easier to follow.
Hello @samuelsinayoko! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on March 26, 2018 at 13:05 Hours UTC |
pandas/core/frame.py
Outdated
column labels) having a hierarchical index with a new inner-most level | ||
of row labels. | ||
The level involved will automatically get sorted. | ||
Stack the prescribed level(s) from the column axis onto the index |
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.
This should be a single line. Can you shorten by "column axis" -> "columns" and "index axis" -> "index"?
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.
Thanks for the review. Fixed in a2c9b1a.
I've also modified the description in the Notes section. It was never completely clear to me why method was called stack (I think I was imagining the column as a board being moved from an horizontal position to a vertical position, whereas I think the name comes from a collection of items being moved from a side by side position to a stack), so I've tried to explain that in the notes section. Hope it makes sense!
@datapythonista Nice seeing you at the London meetup this week, thanks again for organising. Are you happy with the latest changes? |
[ci skip]
Thanks @samuelsinayoko ! |
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.
Checklist for other PRs (remove this part if you are doing a PR for the pandas documentation sprint):
git diff upstream/master -u -- "*.py" | flake8 --diff