Skip to content
Advertisement

Using DataFrame cross join throw no common columns to perform merge on

I’d like to create a third column as a result of a cross join between my Columns A and B:

JavaScript

They have the following unique values:

JavaScript

I’d like to have a df[‘C’] with the combination of all cross joins, thus we should have 6 * 4 = 24 unique values in it:

JavaScript

Thus we should have the following:

JavaScript

Using this method, I have the following error:

JavaScript

Throws:

JavaScript

Any help would be appreciated.

Advertisement

Answer

Why don’t you use the good old itertools:

JavaScript

Output for the example data:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement