1

I have an n-number of pandas DataFrames each containing any number of elements, and I want produce all combinations that can be made by taking one element from each of the DataFrames.

Something like this, where I am showing three different DataFrames and I want to find the combinations that can be made only from column 'a' from each:

Input:
df1 = pd.DataFrame({'a':[1,2]},{'b':[4,4]})
df2 = pd.DataFrame({'a':[7]},{'b':[4,4]})
df3 = pd.DataFrame({'a':[1,5]},{'b':[4,4]})

Output:
1,7,1
1,7,5
2,7,1
2,7,5

I thought there might be a way to use nested for-loops but in not knowing the number of DataFrames, which may also be a large number, I'm not sure of how do that.

The Nightman
  • 5,609
  • 13
  • 41
  • 74

0 Answers0