I came across Ken Wei's comment on this answer stating that using pandas cartesian_product()
while initializing the dataframe with np.array().T
is faster than itertools.product
for combining elements of two lists.
I'm confused as to how it would be used. Given two lists:
l1 = ['A', 'B']
l2 = [1, 2]
How would you arrive at this dataframe using his cartesian_product()
and np.array().T
?
+-----+-----+-----+
| | l1 | l2 |
+-----+-----+-----+
| 0 | A | 1 |
+-----+-----+-----+
| 1 | A | 2 |
+-----+-----+-----+
| 2 | B | 1 |
+-----+-----+-----+
| 3 | B | 2 |
+-----+-----+-----+