Given an arbitrary number of lists, I'd like to produce a pandas DataFrame
as the Cartesian product. For example, given:
a = [1, 2, 3]
b = ['val1', 'val2']
c = [100, 101]
I'd like to end up with a DataFrame
with columns a
, b
, and c
, and all 3x2x2=12 combinations.
Unlike cartesian product in pandas, I'm looking for the ability to provide more than two inputs, and I am not looking to pass DataFrame
s, which would involve keeping values within the same DataFrame
together rather than taking combinations of it. Answers to this question will likely not overlap with answers to that one.
Unlike Cartesian product of x and y array points into single array of 2D points, I'm seeking a pandas DataFrame
result, with named columns, rather than a two-dimensional numpy array.