Skip to content

Conversation

@shiersansi
Copy link
Contributor

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc\source\user_guide\indexing.rst file adding a new feature.

solved problem

BUG: MultiIndex.levels[x] of sliced DataFrame returns values from the non-sliced index #55148
https://github.com/pandas-dev/pandas/issues/55148

Description:

Adding DataFrame.index.levels to doc will show the original value after reducing the data frame reason: pandas only updates the code at slicing time, not the level.

Add content details

屏幕截图 2023-10-07 125621(1)

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @shiersansi. I think you misunderstood a bit the point we're trying to make here. I would say that the main point is that df.index.levels contains the original levels of the multiindex, even if df.index contains less levels.

I think the issue mentioned that we should add this to the MultiIndex.level docstring, not to the user guide, where it's already here: https://pandas.pydata.org/docs/user_guide/advanced.html#defined-levels

Can you please revert the changes here, and add a docstring for MultiIndex.levels instead with this comment? I'll open a new issue to be clearer on what needs to be done.

@rhshadrach

@datapythonista
Copy link
Member

@shiersansi this is the issue: #55435

I'm going to close this PR since I think it'll be easier for you to start from scratch, as everything in this PR needs to be reverted. But you're surely welcome to continue the work on this. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants