Add values of two nested for loops in a dataframe

I have a problem with two nested for loops, that in a simplified fashion would be something like this:

var1 = [1,2]
var2 = [10,20,30]

for i in var1:
     for j in var2:

I want to add those values in each iteration to create a table like this:

Var1 Var2
1 10
1 20
1 30
2 10
2 20
2 30

I thought that the best approach would be to create a dataframe to convert to an excel file. However, I don’t know how to create that dataframe and add the corresponding values in each iteration.

Answer

You can put them both inside a dictionary and append the values inside the loop:

var1 = [1,2]
var2 = [10,20,30]
my_dict = {'var1':[],'var2':[]}
for i in var1:
  for j in var2:
    my_dict['var1'].append(i)
    my_dict['var2'].append(j)
df =pd.DataFrame(my_dict)