Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DOC: Add DataFrame.index.levels #55437
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: Add DataFrame.index.levels #55437
Changes from 3 commits
50ff6c2
f5b7e29
2c8b861
6241262
aac99e1
a3984e1
c11f34a
f2bf96a
164df6f
14be467
f5085f8
1bca09d
ad66dfb
9ea6ebb
329e45c
b871123
ca13b9a
4865b2a
6eaa176
ed8ec94
39eacd2
19298c4
324b682
1e1c873
1d658e0
efe5e0a
596d55c
786abee
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 think the short summary needs to fit in one line. I wouldn't go into technical details like if the return is a tuple. The best I can think of as a short summary is
Levels of the MultiIndex.
. Then in the following paragraph I would explain what are levels, what they mean conceptually, how they can be seen in pandas...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.
In this case this is an attribute (
MultiIndex.levels
notMultiIndex.levels()
), so for the users it doesn't return anything, it contains the value, and this section is not expected to exist. I'm not sure how we do for other attributes in the docs, they can be a good reference.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 reuse the index from above, so this is less verbose please.
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 think it's better to just call this
df
instead oflarge
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 show the dataframe here first, so the user can better understand the data of the example? I think you'll want to avoid using random data in the example, as it'll make your life more difficult. And if you use data that is meaningful instead of some random things, that will also help users understand better. As an idea, you can use a MultiIndex of animals with class/animal (e.g. insect/ant, insect/spides, mammal/goat...) and use a dataframe with just one column, for example number of legs (we use this example in other docs). The example is silly, but meaningful and any user can understand it very quickly, and focus on the concepts, not in understanding the data.
Then, as said, you can show the dataframe first, show the levels of the multiindex from it (i.e.
df.index.levels
), and then you filter the datamany_leg_animals = animals[animals.num_legs > 4]
to finally show that even if now there are no mammals, in the data, the multiindex still contains all the levels.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.
Thank you for your suggestion. Is it easier to understand the example part?
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 a problem that I may need your help with. When I tested the code after I committed it, four tests failed, but I couldn't figure out exactly what went wrong from the error log provided.