Skip to content

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

Merged
merged 1 commit into from
May 25, 2017

Conversation

geoninja
Copy link
Contributor

@geoninja geoninja commented May 23, 2017

Added better examples in the doc for the dataframe set_index() method.

@geoninja
Copy link
Contributor Author

@TomAugspurger @jorisvandenbossche hey, I've just submitted a PR adding a couple of examples to dataframe set_index()

@jreback jreback added the Docs label May 23, 2017
@jreback jreback added this to the 0.21.0 milestone May 23, 2017
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a 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]])
Copy link
Member

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)

Copy link
Contributor

@TomAugspurger TomAugspurger left a 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?

>>> 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],
Copy link
Contributor

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

Copy link
Contributor Author

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.

2 7 84 2013
3 10 31 2014


Copy link
Contributor

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

Copy link
Contributor

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
Copy link

codecov bot commented May 24, 2017

Codecov Report

Merging #16467 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16467   +/-   ##
=======================================
  Coverage   90.42%   90.42%           
=======================================
  Files         161      161           
  Lines       51027    51027           
=======================================
  Hits        46142    46142           
  Misses       4885     4885
Flag Coverage Δ
#multiple 88.26% <ø> (ø) ⬆️
#single 40.17% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/frame.py 97.69% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04356a8...29503fb. Read the comment docs.

@codecov
Copy link

codecov bot commented May 24, 2017

Codecov Report

Merging #16467 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16467   +/-   ##
=======================================
  Coverage    90.4%    90.4%           
=======================================
  Files         161      161           
  Lines       51033    51033           
=======================================
  Hits        46136    46136           
  Misses       4897     4897
Flag Coverage Δ
#multiple 88.24% <ø> (ø) ⬆️
#single 40.17% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/frame.py 97.69% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 97ad3fb...71c5b18. Read the comment docs.

@geoninja geoninja force-pushed the doc-examples#16416 branch from 29503fb to 71c5b18 Compare May 24, 2017 19:24
@jreback
Copy link
Contributor

jreback commented May 24, 2017

lgtm. @TomAugspurger not sure if you had any comments.

@TomAugspurger TomAugspurger merged commit cfcf07b into pandas-dev:master May 25, 2017
@TomAugspurger
Copy link
Contributor

Thanks @geoninja!

@geoninja
Copy link
Contributor Author

Thank you, @TomAugspurger ! I'm also going to work on reset_values() so we can close #16416.

stangirala pushed a commit to stangirala/pandas that referenced this pull request Jun 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants