Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Value error using Pandas and Anaconda

ValueError:The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I have a dataframe with many columns one of which is user_id.

I try the following line of code to threshold users who have less than 10 entries in the dataframe:

myDF.groupby("user_id").filter(lambda x:len(x)>10)

The value of myDF.groupby should be a dictionary with keys as user_ids and corresponding values as lists of integers (representing restaurant codes).

But I receive the aforementioned valueError. I am unable to figure out why this is happening as this worked with previous versions of pandas (when I was working on Enthought Canopy). But recently I made the switch to anaconda by Continuum analytics and this problem seems to be occurring. Does anyone know what I might be doing wrong here?

like image 618
anonuser0428 Avatar asked Mar 21 '26 03:03

anonuser0428


1 Answers

Which version of pandas? This looks like a bug in v0.12 (the first version with filter) that was fixed in v0.13. Update with conda update pandas.

like image 118
Dan Allan Avatar answered Mar 22 '26 15:03

Dan Allan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!