Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Add to_dataframe() method to MultiIndex #12397
Comments
|
can you give an actual usecase? normally you would simply do |
jreback
added API Design MultiIndex
labels
Feb 22, 2016
|
I just searched for this. I have a DF filled with boolean values (an adjacency matrix). I want to store the pairs of labels for which the value is True. I start by doing a simple
now I would like to do
instead I need to do
(admittedly, not a huge problem, but on the other hand |
relativistic
commented
Mar 29, 2016
|
Sorry, missed the notification with @jreback 's comment. One of the nice things about
This is a bit verbose, but admittedly, not bad. The main problem is that this is fragile, and will not work on all DataFrames. It would fail if:
Any one of these problems is relatively easy to get around, if you know a priori the construction of the dataframe. However, its a bit more effort if you want to write a general-purpose function that is guarantied to work in all conditions. And even in the case where you have some idea of your input, it would simply be nice if pandas could deal with this for you so you can focus data analysis, rather than how to wrangle it into the right format. |
|
@relativistic again a fully worked out example here would be instructive. |
relativistic
commented
Mar 29, 2016
|
@jreback : Okay, sure. I'll try to pull together an example some evening soon. Can't show the code I was working on unfortunately, so I'll have to come up with another example. |
|
here is an external impl (e.g. could prob be faster / better if we did this inside of a
|
|
Just for reference: at the time, I ended up doing:
which performs slightly better than (same as above, just to compare on the same CPU):
|
|
@toobaz that's only true for a relatively small frame |
jreback
added a commit
to jreback/pandas
that referenced
this issue
Jan 24, 2017
|
|
jreback |
90b8588
|
jreback
added this to the
0.20.0
milestone
Jan 24, 2017
jreback
added a commit
to jreback/pandas
that referenced
this issue
Jan 24, 2017
|
|
jreback |
396b9db
|
jreback
added a commit
to jreback/pandas
that referenced
this issue
Jan 24, 2017
|
|
jreback |
7193277
|
jreback
added a commit
to jreback/pandas
that referenced
this issue
Jan 25, 2017
|
|
jreback |
4a151c6
|
jreback
added a commit
to jreback/pandas
that referenced
this issue
Jan 25, 2017
|
|
jreback |
c10cad4
|
jreback
added a commit
to jreback/pandas
that referenced
this issue
Jan 25, 2017
|
|
jreback |
595e5e8
|
jreback
added a commit
to jreback/pandas
that referenced
this issue
Jan 25, 2017
|
|
jreback |
b744fb5
|
jreback
closed this
in 7277459
Jan 25, 2017
AnkurDedania
added a commit
to AnkurDedania/pandas
that referenced
this issue
Mar 21, 2017
|
|
jreback + AnkurDedania |
4888ded
|
relativistic commentedFeb 19, 2016
I find the
Index.to_seriesmethod is a convenient way to allow indices to act as columns of a dataframe where desired. However, the behavior ofMultiIndex.to_series, which gives aSeriesof tuples, is less useful.Would it be convenient to provide a
to_dataframemethod for index classes? This would be a natural extension of the utility ofto_series, and more useful forMultiIndexobjects I would think.I'm something equivalent to: