Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas: Unhashable type list

I’m using this code to drop values with condition
df['CNT_CHILDREN'] =df.drop([df['CNT_CHILDREN'] > 10].index)

As an error i have this result

TypeError: unhashable type: 'list'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try:

df = df.drop(df[df['CNT_CHILDREN'] > 10].index)
#            ^--- you forgot df            

df.drop method drop specified labels from rows so you have to pass the index and not the rows themselves.

>>> df[df['CNT_CHILDREN'] > 10].index
Int64Index([3, 5, 8, 13], dtype='int64')  # dummy data
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading