How can I execute a nested loop that goes through two data frames to acquire every combination of the columns within the nested loop. This is for acquiring the various r^2 values across the various combinations utilizing OLS Regression
For example: DF1 consists of:
50 51 52 53
0 73.44 63.44 53.46 44.49
1 395.01 369.01 343.01 317.49
2 339.75 312.76 286.8 262.8
DF2 consists of:
50 51 52 53
0 153.81 173.81 193.83 214.86
1 19.98 23.98 27.98 32.46
2 3.06 5.07 8.11 13.11
How can I get every single combination of both data frame columns and execute the
Here is my code below:
g=50
h=53
for g in range(50, 53):
q =[ round(elem, 2) for elem in DF1[g].iloc[0:].tolist() ]
for h in range(50, 53):
z =[ round(elem, 2) for elem in DF2[h].iloc[0:].tolist() ]
x = np.row_stack((q,z))
x = np.array(x).T
x = sm.add_constant(x)
results = sm.OLS(endog=y, exog=x).fit()
my_list.append(results.rsquared)
h += 1
g+=1
For some reason I am not getting all the combinations of the columns? Any Suggestions?
getting all combinations of columns?