title: Saving Each Iteration of DataFrame "for loop" results as a new array in Python
body: <p>I need to save each iteration results as a new list or Dataframe. I can print the results. But I need to use them in another step of my work. I need each array saved in project.</p>
  <pre><code>import numpy as np
  import pandas as pd
  data = pd.DataFrame()
  m =np.random.randint(1, 30, size = (10, 3))
  df = pd.DataFrame(m, columns = [&quot;var1&quot;, &quot;var2&quot;, &quot;var3&quot;])
  for i in range(0, len(df)+1):
          for j in range(0, len(df)+1):
              if i-j==3:
                  b = df.iloc[j:i]
                  print(b)
  </code></pre>
  <p>Output</p>
  <pre><code>var1  var2  var3
  0    12     1    26
  1     2     2    20
  2     2     8     1
     var1  var2  var3
  1     2     2    20
  2     2     8     1
  3     2     5    26
     var1  var2  var3
  2     2     8     1
  3     2     5    26
  4    18    19    23
     var1  var2  var3
  3     2     5    26
  4    18    19    23
  5    10    18    17
     var1  var2  var3
  4    18    19    23
  5    10    18    17
  6    14     2    16
     var1  var2  var3
  5    10    18    17
  6    14     2    16
  7    15    19    23
     var1  var2  var3
  6    14     2    16
  7    15    19    23
  8     6    27     8
     var1  var2  var3
  7    15    19    23
  8     6    27     8
  9    11     1    11
  </code></pre>
  <p>When I try to save them into new array, I tried to add this code below;</p>
  <pre><code>import numpy as np
  import pandas as pd
  data = pd.DataFrame()
  m =np.random.randint(1, 30, size = (10, 3))
  df = pd.DataFrame(m, columns = [&quot;var1&quot;, &quot;var2&quot;, &quot;var3&quot;])
  for i in range(0, len(df)+1):
          for j in range(0, len(df)+1):
              if i-j==3:
                  b = df.iloc[j:i]
                  for k in range (0,9):
                      a = &quot;erkan_&quot; + str(k+1)
                      globals()[&quot;erkan_%s&quot; % (j)] = b
                      print(&quot;{0} = {1}&quot;. format(a, b))
  </code></pre>
  <p>it creates list names as erkan_1, erkan_2, ..., erkan_8
  but saves last results. Could you help me please?</p>