This question is related to How to concatenate combinations of rows from two different dataframes? but with a minor twist.
I have two dataframes with a common column. I want to create a new dataframe whose column names are the common column plus the concatenation of the two dataframes columns.
The resulting dataframe will have all possible combinations (cartesian product?) between rows of the two datasets that have the same value in the common column.
The two original datasets are:
df1 = pd.DataFrame({'common': ['x', 'y', 'y'], 'A': ['1', '2', '3']})
df2 = pd.DataFrame({'common': ['x', 'x', 'y'], 'B': ['a', 'b', 'c']})
and the resulting dataset would be:
df3 = pd.DataFrame({'common': ['x', 'x', 'y', 'y'],
'A': ['1', '1' '2', '3'],
'B': ['a', 'b', 'c', 'c']})