title: Creating and modifying dataframes with a for loop python
body: <p>I am new to Python and StackOverflow. Hopefully I post correctly :)</p>
  <p><strong>Problem:</strong> In each for loop I am attempting to create a new dataframe, add columns to it, and fill the columns with data.</p>
  <p><strong>Methodology:</strong> Reading through previous posts, I have learnt I can create new dataframes using &quot;exec&quot; but this is not best practice. Alternatively I can create a dic and modify the df after. Have been trying to use embedded for loops as well</p>
  <p><strong>Issue:</strong> Actually modifying and filling in the created (and empty) df</p>
  <p><strong>Code:</strong></p>
  <pre><code>df1 = an existing dataframe with date as its index and profit, tax, and revenue for columns 
  #tablelist will only have these 4 values
  tablelist = ['QTD','YTD','OneYear','Inception']
  
  # Method 1
  for table in tablelist:
       #this works
       exec('{} = pd.DataFrame()'.format(table))
       #this doesn't work 
       table['Value'] = df1[profit] - df1[tax]
  
  ---&gt; error: 'str' object does not support item assignment
  
  # Output (without line 4)
  
  type(YTD)
  pandas.core.frame.DataFrame
  
  #this works but its outside of the loop so it defeats purpose
  YTD['Value'] = df1[profit] - df1[tax]                           
  </code></pre>
  <p>Method 1 does not to help since its outside the loop.</p>
  <pre><code># Method 2
  d = {}
  for i in tablelist1:
      #this works but I cant figure out how add columns and data
      d[i] = pd.DataFrame()
  
  # Output
  
  print(d)
  
  {'QTD': Empty DataFrame
   Columns: []
   Index: [], 'YTD': Empty DataFrame
   Columns: []
   Index: [], 'OneYear': Empty DataFrame
   Columns: []
   Index: [], 'Inception': Empty DataFrame
   Columns: []
   Index: []}
  </code></pre>
  <p>Method 2 works but how do I add columns and data?</p>
  <p>Any advice is greatly appreciated!!</p>