title: Need help refining code to run a for loop to summarize economic variables from a csv file?
body: <p>I have a csv file with a time series of two economic variables (housing starts and Unemployment). I have a list of calculations and a summary (text) that is written with the output of the calculations (basically summarizing in a paragraph format what the trends are of the data). I would like feedback on how i get I get a for loop to go through each variable in the csv file so i have a summary for each variable as the final output. </p>
  
  <p>I tried applying the basic logic of a for loop but I'm just not sure what i have incorrect. I looked at a number of examples on stackoverflow but nothing seems to fit, I'm sure I'm missing something simple but haven't been using python that long so just not sure at this point. </p>
  
  <pre class="lang-py prettyprint-override"><code>raw_data = pd.read_csv('C:/Users/J042666/Desktop/2019.03 HOUST and GDP.csv')
  df = pd.DataFrame(raw_data)
  
  for i in df:
  
      freq = "monthly "
      units = " million "
      pos = 1
      colname = df.columns[pos]
  
      alltime = df.mean()
      low = df.min()
      maximum = df.max()
      today = df.iloc[720]
      one_year = df.iloc[709:721].mean()
      two_year = df.iloc[697:721].mean()
      five_year = df.iloc[661:721].mean()
      one_year_vol = df.iloc[709:721].std()
      two_year_vol = df.iloc[697:721].std()
      five_year_vol = df.iloc[661:721].std()
      today_vs_1 = ((today/one_year) -1)*100
      today_vs_2 = ((today/two_year) -1)*100 
      today_vs_5 = ((today/five_year) -1)*100
      rolling_1 = df.rolling(window=3).mean()
      rolling_2 = df.rolling(window=6).mean()
      rolling_3 = df.rolling(window=9).mean()
      today_vs_1_rolling = ((today/rolling_1.iloc[720]) -1)*100
      today_vs_2_rolling = ((today/rolling_2.iloc[720]) -1)*100 
      today_vs_3_rolling = ((today/rolling_3.iloc[720]) -1)*100
      summary = ("The " + str(freq) + str(colname) + " currently stands at " + str(today) + str(units) + " which compares to the 1,2 and 5 year averages of " + str(one_year) + str(units) + "," + str(two_year) + str(units) + "," + " and " + str(five_year) + str(units) + " respectively. " + " Based on the current " + str(colname) + " levels, that reflects a change of" + str(today_vs_1) + ", " + str(today_vs_2) + " and " + str(today_vs_5) + " respectively." " Since the metric began being tracked, the minimum, maximum and long run average total " + str(low) + str(units) + ", " + str(maximum) + str(units) + " and " + str(alltime) + str(units) + " respectively. " "The 1, 2 and 5 year standard deviation for " + str(colname) + " totals " + str(one_year_vol) + str(units) + " ," + str(two_year_vol) + str(units) + " and" + str(five_year_vol) + str(units) + " respectively." + " Based on the current " + str(colname) + " levels compared to the 3, 6 and 9 month rolling averages, the current level reflects a change of " + str(today_vs_1_rolling) + ", " + str(today_vs_2_rolling) + " and " + str(today_vs_3_rolling) + " respectively.")
  print(summary)
  </code></pre>
  
  <p>As I describe above, I am hoping to have code that produces a paragraph summary of the financial metrics i calculate in the for loop for each variable.</p>