0

I got a list containing row indexes to delete. The list contains duplicates so to lighten the burden I tried to remove duplicate entries:

invalid_rows = list(dict.fromkeys(invalid_rows))

Returning: TypeError: unhashable type: 'list'

Okey, well let's try with duplicate values just to see if I can remove the rows:

df = df.drop(index=invalid_rows)

Returning the same error code. What's the problem with the list? I tried to google but I can't seem to find the error.

1

2 Answers 2

1

I am guessing that invalid_rows is not a list, it is actually a nested list. fromkeys method tries to use elements of that list as keys for dictionary, but since its elements (at least one of them) are not hashable type, it raises an error.

Sign up to request clarification or add additional context in comments.

Comments

1

A simple way to remove duplicates from a list would be:

invalid_rows = list(set(invalid_rows))

This of course assumes invalid_rows is a list of hashable items

2 Comments

The error already says that invalid_rows contains an unhashable type.
Thanks, it seem like my list is nested for some reason. Will try to figure it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.