0

I need to find intersection between two pandas dataframes based on a column of lists named "authors".enter image description here

But instead I get this error:

enter image description here

1
  • You need to show us what you tried. And as much as possible, paste the the code and errors here instead of providing screenshots. Make it easy for us to help you and you're likely to see more answers. Commented Jun 23, 2017 at 3:03

1 Answer 1

3

You cannot merge on a list, because list cannot be hashed, see this. One option would be to create an additional column by converting list to string and merge on it, e.g.:

df['authors_as_string'] = df['authors'].apply(lambda x: "-".join(x))

This would produce:

   id    authors authors_as_string
0   1  [a, b, c]          a-b-c
1   2  [a, b, c]          a-b-c
2   3     [a, b]            a-b
3   4     [a, c]            a-c

Then you can merge on that third column.

Alternatively you can try other solutions posted in that question.

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

Comments

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.