-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
ENH: Melt with MultiIndex columns #4150
Conversation
tbh I'm not 100% if this is the right behaviour... thoughts? |
slightly OT: is there a corresponding |
using i guess pivot tables are really unmelting...so maybe not that useful |
No idea at all why it's called melt... |
not that I know anything about R, but that's where it comes from...... |
@jreback that's one step back in it's history, would be nice to know where it originated from... maybe I'll ask on SO, no doubt I'll be downvoted into oblivion. |
@hayd I may be in the minority, but I think |
or 0.12? |
@hayd i can ask on SO if you want i only have 331 rep so oblivion is a jump, skip and a hop away. |
@cpcloud Up to you, I had penned a partial question (but I'd need to research more before posting, so may leave for another day)... I'il upvote if you beat me to it :p I'm thinking it called it because it's the opposite of "cast" (though no idea if there is a difference between cast and pivot) http://www.statmethods.net/management/reshape.html :s |
i like how this is in the R docs for cast.
Everything in R can be done with exactly 3 functions. |
@hayd I think you're right there's all sorts of talk about "molten" |
@cpcloud personally think it's a rather confusing/strange analogy... |
@hayd Well, you know, R has to keep the barrier to entry very high by using obscure analogies |
@hayd are you suggesting that we change the name for |
personally i think |
I think melt is pretty descriptive... |
how are you thinking about it? or do i detect sarcasm over github? i think of it like a "generalized-for-labels" i actually don't use this much but now i'm starting to see where this might be useful in my own work... |
I wouldn't be unhappy to see an unpivot alias for melt (or vice versa), but then should cast be an alias for pivot (or pivot_table)? shudders |
I am -1 on |
cast is a horrible name |
what was |
as confusing as possible, but no more |
Well written documentation
|
"shape-casting" should not be called casting, it should be called reshaping (strangely enough, that's the name of the package containing |
okay so then deprecate |
|
yes..its just |
Will put this together (either as separate pr or on the top of this... or will push on top). |
Think I should also add a note about pivot vs pivot_table (is melt the inverse of pivot or pivot_table?) Will I sometimes not be able to roundtrip with pivot? re this question/answer, not clear to me the purpose of pivot... strictness I suppose. |
I believe (and |
Yeah that's what I think to (I think pivot required every entry to exist, which pivot_table can live with missing data), question I have is does melt always return something which can be pivoted? |
I think the identity is not always true (it COULD be but is not required to be true)..... then again I could be FOS |
pd.pivot works with numpy arrays so maybe it makes sense there. melt doesn't drop the NAs:
So it is the inverse of pivot, agree to dropna option (but 0.12 may be optimistic for that bit) in which case pivot_table would be needed to invert it. |
Just to come full circle and be clear I would really like melting of multi-index frames. |
ok...so maybe for 0.12
for 0.13 figure out when roundtripping |
@cpcloud ok, shall we just merge this one now then? ... I think the suggested behaviour makes sense. |
i can't play with it at this exact moment so if u can wait a couple of hours that would be great otherwise if others think it's ok then merge away! |
I don't see a reason to deprecate melt. There is indeed quite a bit you can do with |
@wesm care to elaborate for those of us (like myself) who aren't that familiar with R? Links to examples might be nice as well, then we can open up some issues. Thanks! |
Recommend reading the reshape2 documentation |
its just a deprecate on the name |
|
||
if isinstance(frame.columns, MultiIndex): | ||
for i, col in enumerate(var_name): | ||
mdata[col] = np.asarray(frame.columns.get_level_values(i)).repeat(N) |
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.
it seems like you might be able to remove the else
below in favor of this, it looks more general, no?
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.
True, just wondering how obvious this is (if there are any edge cases), suppose would be good to allow list for an index... not sure. Will try and have another look tomorrow..
@hayd i went ahead and did it for u + some clean up of doctests travis build: branch: |
@hayd thanks! |
@jreback already a note in release, sorry I accidentally deleted your question (past my bed-time)... |
@hayd np.....I think looks good...basicaly just adding the mi-melt here, no rename/deprecate....can address in 0.13 |
will make a separate pr (too late for this kind of thing in 0.12 anyways). imo could have melt as is, but unpivot could have additional feature of a dropna argument (i.e. melt is an alias for unpivot(dropna=False). But will put together pr and we can argue there :) Seems like no qualms about behaviour in the pr, so merge? |
merge |
ENH: Melt with MultiIndex columns
btw molten/melt and cast come from this paper i believe, or maybe from his phd thesis |
No idea if there's actually a market for this, but anyhow:
Also includes fix for
get_level_values
and name attribute.cc #4144