Skip to content

DOC: MultiIndex Indexing Using Slices #5280

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

Closed
cancan101 opened this issue Oct 20, 2013 · 10 comments
Closed

DOC: MultiIndex Indexing Using Slices #5280

cancan101 opened this issue Oct 20, 2013 · 10 comments

Comments

@cancan101
Copy link
Contributor

I have the following DataFrame:

    t1  t2
    b1  b1
i1   1   1

which I can index like this:

In [139]: df["t1"]
Out[139]: 
    b1
i1   1

In [140]: df["t1","b1"]
Out[140]: 
i1    1
Name: (t1, b1), dtype: int64

In [141]: df["t1"]["b1"]
Out[141]: 
i1    1
Name: b1, dtype: int64

I would expect this to work, but ti does not:

In [142]: df[:]["b1"]
KeyError: 'b1'

as well as this (which also raises an unhelpful error message):

In [143]: df[:,"b1"]
TypeError: 
@jreback
Copy link
Contributor

jreback commented Oct 20, 2013

pls read the docs

http://pandas.pydata.org/pandas-docs/dev/indexing.html

those operations are not supported in that format (and have never been), nor will for good reason

@cancan101
Copy link
Contributor Author

@jreback I have read those docs. Okay, Is this there any easy way to accomplish dropping a level of column name hierarchy?

Also the second exception (TypeError) is not very helpful.

@cancan101
Copy link
Contributor Author

So far my best option is:

df.T.reset_index(level=1, drop=True).T

@jorisvandenbossche
Copy link
Member

@cancan101 df.columns = df.columns.droplevel()

@cancan101
Copy link
Contributor Author

  1. This feature is undocumented (http://pandas.pydata.org/pandas-docs/dev/search.html?q=droplevel&check_keywords=yes&area=default#)
  2. Does it make sense to have an inplace option?

@jorisvandenbossche
Copy link
Member

And there are still some more things that are undocumented. PR?

The methods specific to MultiIndex are:

pandas.MultiIndex.droplevel
pandas.MultiIndex.equal_levels
pandas.MultiIndex.from_arrays
pandas.MultiIndex.from_tuples
pandas.MultiIndex.get_loc_level
pandas.MultiIndex.get_major_bounds
pandas.MultiIndex.has_duplicates
pandas.MultiIndex.is_lexsorted
pandas.MultiIndex.levshape
pandas.MultiIndex.lexsort_depth
pandas.MultiIndex.reorder_levels
pandas.MultiIndex.sortlevel
pandas.MultiIndex.swaplevel
pandas.MultiIndex.truncate

@jtratner
Copy link
Contributor

Please don't document them right now - many of those are more internal than
external and it's possible we'll be changing or deprecating some of them in
the next release. I'd prefer not to put them in docs until we've decided
which are actually supposed to be used by end users. Definitely will be
documented in 0.14

@cancan101
Copy link
Contributor Author

Should we create a ticket to keep track of the eventual documentation?
On Oct 20, 2013 1:11 PM, "Jeff Tratner" [email protected] wrote:

Please don't document them right now - many of those are more internal than
external and it's possible we'll be changing or deprecating some of them in
the next release. I'd prefer not to put them in docs until we've decided
which are actually supposed to be used by end users. Definitely will be
documented in 0.14


Reply to this email directly or view it on GitHubhttps://github.com//issues/5280#issuecomment-26677372
.

@jreback
Copy link
Contributor

jreback commented Feb 18, 2014

related is #6301

@jreback
Copy link
Contributor

jreback commented Mar 30, 2014

this is effectively closed by #6301.

The documentation will be done when Index is refactored,

@jreback jreback closed this as completed Mar 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants