-6

What's the best way to create a pandas dataframe to get every possibility with some list of numbers?

I want to test every configuration of an algorithm.

Lists are like

a = [0,1,2,3,4,5,6,7]
b = [0.0001, 0.0002, 0.0003]
c = ...
'''

And i need to get a dataframe which get in each row

row 1 = a[0],b[0],c[0]
row 2 = a[0],b[1],c[0]
row 3 = a[0],b[0],c[1]
row 4 = a[0],b[2],c[0]
row 5 = a[0],b[2],c[1]

Of course i get like 7 lists and each lists have more than 3 numbers.

Thanks for the help guys Have a nice day.

Stitry
  • 23
  • 4
  • 2
    Hi, what is it that you tried for this? –  Jan 12 '22 at 21:40
  • "python permutations of a list" -> https://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list might be a useful starting point – msanford Jan 12 '22 at 21:41

1 Answers1

0

Use itertools.product:

from itertools import product

a = [0,1,2,3,4,5,6,7]
b = [0.0001, 0.0002, 0.0003]
c = [10, 20]

df = pd.DataFrame(product(a, b, c), columns=list('abc'))
print(df)

# Output
    a       b   c
0   0  0.0001  10
1   0  0.0001  20
2   0  0.0002  10
3   0  0.0002  20
4   0  0.0003  10
5   0  0.0003  20
6   1  0.0001  10
7   1  0.0001  20
8   1  0.0002  10
9   1  0.0002  20
10  1  0.0003  10
11  1  0.0003  20
12  2  0.0001  10
13  2  0.0001  20
14  2  0.0002  10
15  2  0.0002  20
16  2  0.0003  10
17  2  0.0003  20
18  3  0.0001  10
19  3  0.0001  20
20  3  0.0002  10
21  3  0.0002  20
22  3  0.0003  10
23  3  0.0003  20
24  4  0.0001  10
25  4  0.0001  20
26  4  0.0002  10
27  4  0.0002  20
28  4  0.0003  10
29  4  0.0003  20
30  5  0.0001  10
31  5  0.0001  20
32  5  0.0002  10
33  5  0.0002  20
34  5  0.0003  10
35  5  0.0003  20
36  6  0.0001  10
37  6  0.0001  20
38  6  0.0002  10
39  6  0.0002  20
40  6  0.0003  10
41  6  0.0003  20
42  7  0.0001  10
43  7  0.0001  20
44  7  0.0002  10
45  7  0.0002  20
46  7  0.0003  10
47  7  0.0003  20
Corralien
  • 109,409
  • 8
  • 28
  • 52