1

I have some taps. There are n of them. Each tap can either be off or on. I would like to generate a dataframe of all of the possible states that my set of taps could be in. For example if

n=2

Then I would like to generate the dataframe

enter image description here

R. Cox
  • 819
  • 8
  • 25

1 Answers1

2

Use itertools.product with DataFrame constructor:

from  itertools import product

n = 2
df = pd.DataFrame(list(product(range(2), repeat=n)))

print (df)
   0  1
0  0  0
1  0  1
2  1  0
3  1  1
R. Cox
  • 819
  • 8
  • 25
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252