-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Add to_dataframe() method to MultiIndex #12397
Comments
can you give an actual usecase? normally you would simply do |
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 |
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. |
@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 |
ENH: allow hashing of MultiIndex closes pandas-dev#12397
ENH: allow hashing of MultiIndex closes pandas-dev#12397
ENH: allow hashing of MultiIndex closes pandas-dev#12397
closes pandas-dev#12397 Author: Jeff Reback <jeff@reback.net> Closes pandas-dev#15216 from jreback/to_dataframe and squashes the following commits: b744fb5 [Jeff Reback] ENH: add MultiIndex.to_dataframe
I find the
Index.to_series
method is a convenient way to allow indices to act as columns of a dataframe where desired. However, the behavior ofMultiIndex.to_series
, which gives aSeries
of tuples, is less useful.Would it be convenient to provide a
to_dataframe
method for index classes? This would be a natural extension of the utility ofto_series
, and more useful forMultiIndex
objects I would think.I'm something equivalent to:
The text was updated successfully, but these errors were encountered: