0

I want to create a dataframe with 8 columns

Each cell can have 5 possible values

"strongly agree", "agree", "disagree", "strongly disagree" and NaN

I want to generate a dataframe with all the possibilities (permutations/combinations) so that I can use this dataframe for further processing.

Is it possible to generate this dataframe? In python or R ?

To Summarize, A Dataframe with 8 columns and 5 combination of values. 5^8 rows of data should be there in the dataframe

Bella_18
  • 624
  • 1
  • 14

1 Answers1

5

IIUC, you want a cartesian product. You can use itertools.product:

from itertools import product

values = ["strongly agree", "agree", "disagree", "strongly disagree", pd.NA]

df = pd.DataFrame(product(values, repeat=8))

output:

                     0               1               2               3               4               5               6                  7
0       strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly agree     strongly agree
1       strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly agree              agree
2       strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly agree           disagree
3       strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly agree  strongly disagree
...
390620            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>     strongly agree
390621            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>              agree
390622            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>           disagree
390623            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>  strongly disagree
390624            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>            <NA>               <NA>
mozway
  • 194,879
  • 13
  • 39
  • 75