Q: Merging data frame generating extra coma I have the following data frames
b = frozenset({'hi','how','are'})
c = frozenset({'we'})

d = frozenset({'hi','how'})
e = frozenset({'we','are'})

we = set()
we.add((b,c))

we2 =set()
we2.add((d,e))

import pandas as pd
df = pd.DataFrame({'we': [we,we],'value': [5,2]})
df2 = pd.DataFrame({'we': [we2,we],'value': [6,12]})

df is :
               we             value
0   {((hi, how, are), (we))}    5
1   {((hi, how, are), (we))}    2

Here is df2:
               we             value
0   {((hi, how), (are, we))}    6
1   {((hi, how, are), (we))}    12

I left joined df and df2:
df.we = df.we.apply(tuple)
df2.we = df2.we.apply(tuple)
df3= pd.merge(df,df2,how='left',on='we')

The result is correct in terms of data but I have no idea where did the comas come from:
                  we        value_x value_y
0   (((hi, how, are), (we)),)   5   12
1   (((hi, how, are), (we)),)   2   12

How do I get:
                  we    value_x value_y
0   ((hi, how, are), (we))  5   12
1   ((hi, how, are), (we))  2   12


A: You do not want to convert the set to a tuple but extract its only element.
df.we = df.we.apply(lambda x: next(iter(x)))
df2.we = df2.we.apply(lambda x: next(iter(x)))
df3= pd.merge(df,df2,how='left',on='we')

df3 is as expected
                       we  value_x  value_y
0  ((are, how, hi), (we))        5       12
1  ((are, how, hi), (we))        2       12


Alternatively, you could update your sets with the sequences instead of adding to them:
...
we = set()
we.update((b,c))

we2 =set()
we2.update((d,e))

For example df would be:
                       we  value
0  ((we), (are, how, hi))      5
1  ((we), (are, how, hi))      2

Now it makes sense to convert the set to a tuple and after:
df.we = df.we.apply(tuple)
df2.we = df2.we.apply(tuple)
df3= pd.merge(df,df2,how='left',on='we')

we also get for df3:
                       we  value_x  value_y
0  ((hi, are, how), (we))        5       12
1  ((hi, are, how), (we))        2       12

