Create a dataframe of permutations in pandas from list

Viewed 11056

I have the following lists:

aa = ['aa1', 'aa2', 'aa3', 'aa4', 'aa5']
bb = ['bb1', 'bb2', 'bb3', 'bb4', 'bb5']
cc = ['cc1', 'cc2', 'cc3', 'cc4', 'cc5']

I want to create a pandas dataframe as such:

aa    bb    cc
aa1   bb1   cc1
aa2   bb1   cc1
aa3   bb1   cc1
aa4   bb1   cc1
aa5   bb1   cc1
aa1   bb2   cc1
aa1   bb3   cc1
aa1   bb4   cc1
aa1   bb5   cc1
aa1   bb1   cc2
aa1   bb1   cc3
aa1   bb1   cc4
aa1   bb1   cc5

I'm stuck as to how to do this. I've looked at examples: How to generate all permutations of a list in Python

I can do each permutation individually using:

import itertools
itertools.permutations(['aa1','aa2','aa3','aa4','aa5'])

I have a few tens of lists and ideally, I'd like to do them automatically.

Appreciate any help!

2 Answers
Related