title: Dynamically Generating Variables for Dataframe values Assignment
body: <p>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.</p>
  <p>The following code is what I would like to generate dynamically: <code>test_df.loc[i,asignment_list[ii]] = i</code>.</p>
  <p>The example code below is only calling for 3 random columns.
  import pandas as pd</p>
  <pre><code>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)
  </code></pre>
  <p>Output:</p>
  <p><a href="https://i.stack.imgur.com/SFCkK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SFCkK.png" alt="enter image description here" /></a></p>
  <p>I did trying the below piece of code but it requires that I call the variable name which can't be done dynamically.</p>
  <pre><code>for ii in range(0,3,1):
      globals()[f'test_df.loc[{i},asignment_list[{ii}]'] = i
  </code></pre>
  <p>If python does not have this functionality could I build it into python with C?</p>