-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TypeError: unhashable type: 'dict' when using apply/transform? #17309
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
Comments
@jorisvandenbossche @jreback same bug with
only
is this a nasty bug? |
agg is more general that apply
i guess it should work |
@jreback yes, thanks, that's correct this is what I am saying as well: it works with However, I do not want to aggregate, I want to use a What do you think? Thanks again! |
if you want to submit a PR to fix it, by all means. (your example didn not indicate transform) |
Has this been fixed yet? I think transform after groupby is a very useful feature to have. |
Still open. Please let us know if you want to start a PR to fix this. |
Is there any reason the documentation says that transform takes a dictionary, when it doesn't? |
Transform also doesn't take a list, as the documentation says it does. To use the above example:
...returns "TypeError: unhashable type: 'list'" |
Would like to see this fixed too as an aggregate variant of transform would be very handy |
I'm also confused by the documentation. Isn't there an easy way to transform just one column of a grouped DataFrame? |
In pandas version 0.23.4, after group by a dataframe, it can not pass transform method a list of functions and can not rename the field name of a transformed dataframe using a nested dictionary, but it is very useful !! |
@zeromh The referenced documentation where
|
Can this then be taken as a feature request, so that the same kind of |
Vote it! It is very useful |
@colin1alexander |
@jreback @TomAugspurger |
Yeah, that sounds about right. @WillAyd may have better thoughts on how to start. Keep in mind, doing this for With |
Reading through the comments here I think there have been quite a few things talked about, but just so we are on the same page I assume we are explicitly talking about changing Not objected to it though I think it makes more sense if we updated |
guys, as the original OP and lifelong
This used to work back in the days with the good old This is very unfortunate because in one go I was able to use multiple functions on a single column (here Do you think that syntax could be used in Thanks!! |
We have a separate issue for an alternative to the deprecated dict of dicts in agg. Hoping to have that for 0.24.
…________________________________
From: Olaf <[email protected]>
Sent: Saturday, October 13, 2018 10:43:47 PM
To: pandas-dev/pandas
Cc: Tom Augspurger; Mention
Subject: Re: [pandas-dev/pandas] TypeError: unhashable type: 'dict' when using apply/transform? (#17309)
guys, as the original OP and lifelong pandas supporter, let me reiterate that it would be very useful to have apply, transform, and agg be able to work like this:
test.groupby('groups').transform(
{'value1' : {'value1_mean' : 'mean', 'value1_max' : 'max'},
'value2' : {'value2_mean' : 'mean'}})
This used to work back in the days with the good old agg. It does not anymore.
This is very unfortunate because in one go I was able to use multiple functions on a single column (here mean and max on value1) as well as rename them on the fly (so that these variables have the names I have chosen and the dataframe does not have some weird multicolumn index)
Do you think that syntax could be used in apply, transform and agg? This syntax was just a great idea.
Thanks!!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#17309 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABQHIiMk5mlzkrV61ONerWwlPkNE6EN3ks5ukrLzgaJpZM4O-ueX>.
|
@TomAugspurger thanks but we re talking about extending that to |
@WillAyd
|
My point is that it would make more sense to make sure this works: test.groupby('groups').transform([np.mean, max]) Before attempting: test.groupby('groups').transform({'value1': [np.mean, max]) Because the mechanisms to ensure that the list of functions are acceptable will probably be "reused" when it comes time to accepting a value from a dictionary which is a list Somewhat of a side note but the hierarchical column structure of the result is going to be entangled somewhat in the #18366 (comment). I don't believe that should be a blocker but just a consideration point for devs |
Hi everyone, |
I just stumbled upon this and after checking the docs at padas 0.24.2 DataFrame.transform I see that it still says that dict is supported as |
Also, is there any advance on getting the desired feature into a next release? I'm been using pandas for a while now but never actually attempted to contribute. I can try to implement this with a little guidance if someone is willing to help me out. |
@elpablete you linked to DataFrame.transform. That would be a different issue. This is about DataFrameGroupBy.transform. |
@TomAugspurger I cannot find the docs for "DataFrameGroupBy.transform". I found That's my point when I say it's very confusing. |
maybe could provide a more helpful error message (with link to groupby.transform/apply docs) and maybe raise NotImplementedError in the short term |
Hello!
I am quite puzzled by some inconsistencies when using
apply
. Consider this simple exampleNow, this WORKS
but this FAILS
This worked in prior versions of Pandas. What is the new syntax then? Some very useful variant of the code above I used to use was:
to rename the new variables on the fly. Is this still possible now? Is this a bug?
Many thanks!
The text was updated successfully, but these errors were encountered: