-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: add examples to set_index method #16467
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
Conversation
@TomAugspurger @jorisvandenbossche hey, I've just submitted a PR adding a couple of examples to dataframe set_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.
Looking good!
@@ -2947,9 +2947,37 @@ def set_index(self, keys, drop=True, append=False, inplace=False, | |||
|
|||
Examples | |||
-------- | |||
>>> indexed_df = df.set_index(['A', 'B']) | |||
>>> indexed_df2 = df.set_index(['A', [0, 1, 2, 0, 1, 2]]) | |||
>>> indexed_df3 = df.set_index([[0, 1, 2, 0, 1, 2]]) |
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.
For this case, it would also be nice to add an example (so what this is doing is passing the actual index values, instead of a column name to set as 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.
Looks good. Just some trailing spaces to cleanup. Mind pushing a fix for that?
pandas/core/frame.py
Outdated
>>> indexed_df2 = df.set_index(['A', [0, 1, 2, 0, 1, 2]]) | ||
>>> indexed_df3 = df.set_index([[0, 1, 2, 0, 1, 2]]) | ||
>>> df = pd.DataFrame({'month': [1,4,7,10], | ||
... 'year': [2012,2014,2013,2014], |
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.
maybe add spaces after the commas so that this follows PEP8
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 already done that and added an extra example. I will update soon.
pandas/core/frame.py
Outdated
2 7 84 2013 | ||
3 10 31 2014 | ||
|
||
|
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.
You should be able to remove one of these lines.
4 40 2014 | ||
7 84 2013 | ||
10 31 2014 | ||
|
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.
Same here (remove one)
Codecov Report
@@ Coverage Diff @@
## master #16467 +/- ##
=======================================
Coverage 90.42% 90.42%
=======================================
Files 161 161
Lines 51027 51027
=======================================
Hits 46142 46142
Misses 4885 4885
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16467 +/- ##
=======================================
Coverage 90.4% 90.4%
=======================================
Files 161 161
Lines 51033 51033
=======================================
Hits 46136 46136
Misses 4897 4897
Continue to review full report at Codecov.
|
29503fb
to
71c5b18
Compare
lgtm. @TomAugspurger not sure if you had any comments. |
Thanks @geoninja! |
Thank you, @TomAugspurger ! I'm also going to work on reset_values() so we can close #16416. |
git diff upstream/master --name-only -- '*.py' | flake8 --diff
Added better examples in the doc for the dataframe set_index() method.