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")
>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)