Skip to content

Instantly share code, notes, and snippets.

@scdub
Last active April 7, 2021 00:43
Show Gist options
  • Save scdub/b0ac871dbb54e68c136d346a55e517a5 to your computer and use it in GitHub Desktop.
Save scdub/b0ac871dbb54e68c136d346a55e517a5 to your computer and use it in GitHub Desktop.
import itertools
import pandas as pd
values = [('A', 'B', 'C'),
('1', '2', '3'),
('P', 'Q', 'R')]
df = pd.DataFrame([''.join(p) for p in itertools.product(*values)])
"""
0
0 A1P
1 A1Q
2 A1R
3 A2P
4 A2Q
5 A2R
6 A3P
7 A3Q
8 A3R
9 B1P
10 B1Q
11 B1R
12 B2P
13 B2Q
14 B2R
15 B3P
16 B3Q
17 B3R
18 C1P
19 C1Q
20 C1R
21 C2P
22 C2Q
23 C2R
24 C3P
25 C3Q
26 C3R
"""
@danmaps
Copy link

danmaps commented Apr 6, 2021

there is a little typo up there where lists is used instead of values...
df = pd.DataFrame([''.join(p) for p in itertools.product(*values)])

@scdub
Copy link
Author

scdub commented Apr 7, 2021

@danmaps I knew I should've written tests! Fixed now, thanks for the catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment