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

TypeError: unhashable type: 'list' while self joining a dataframe?

I have a dataframe df which is as follows.I have made this column "FN3LN4ZIP" using another larger dataframe.Now when I am self joining it,it is giving error, TypeError: unhashable type: ‘list’ .What could be the reason and how to solve it.
-When I am doing same for another column for bigger dataset,it is self joining easily.

  df:
  CustID    FN3LN4ZIP
    1   [ABY|MACL|153]
    2   [ABY|MACL|153]
    3   [AD|NBO|4103]
    4   [AY|NABO|7981]
    5   [ADE|LPK|7981]

Using following codes to self join:

df = pd.merge(df,df,on="FN3LN4ZIP",how = "inner")

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 :

Since you can’t join on list type, you can map your column to string in order to merge then map it back to the original list type

import ast
df["FN3LN4ZIP"]= df["FN3LN4ZIP"].map(str)
pd.merge(df,df,on="FN3LN4ZIP",how = "inner")
df["FN3LN4ZIP"]= df["FN3LN4ZIP"].map(ast.literal_eval)
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