I am trying to make the below code more dynamic. I have left out all code that is not relevant for simplicity. What follows is the whole concept for the program. The objective is to build linear models from random columns. The way it working is x numbers of random columns are selection and then those columns are used to build a linear model. That model is used on a test dataset and relevant information is captured in a dataframe. This will continues a large number of times. What I would like to do is to be able to generation the code that is used to assign the values to the dataframe dynamical based on the number of columns selected. Otherwise I need to keep the number of columns selected static. With a consequence that I babysit the program while it runs and I manual index the number of columns selected.
The following code is what I would like to generate dynamically: test_df.loc[i,asignment_list[ii]] = i.
The example code below is only calling for 3 random columns. import pandas as pd
test_df = pd.DataFrame(columns = {'a','b','c','d','e','f','g','h','i','j'})
for i in range(10):
asignment_list = list(test_df.sample(n = 3, replace = True, axis = 1))
test_df.loc[i,asignment_list[0]] = i
test_df.loc[i,asignment_list[1]] = i
test_df.loc[i,asignment_list[2]] = i
print(test_df)
Output:
I did trying the below piece of code but it requires that I call the variable name which can't be done dynamically.
for ii in range(0,3,1):
globals()[f'test_df.loc[{i},asignment_list[{ii}]'] = i
If python does not have this functionality could I build it into python with C?

