title: Dataframe and updating a new column value in a for loop
body: <p>I am trying to update a value in a dataframe using a method and a forloop. I pass the dataframe into the method and use a for loop to calculate the value I want to put into the last column.</p>
  <p>Here is the method</p>
  <pre><code>def vwap2(df):
  sumTpv = 0.00
  sumVolume = 0
  dayVwap = 0.00
  
  for i, row in df.iterrows():
      #Get all values from each row
      
      #Find typical price
      tp = (row['HIGH'] + row['LOW'] + row['CLOSE'] + row['OPEN']) / 4
      tpv = tp * row['VOLUME']
      sumTpv= sumTpv + tpv
      sumVolume = sumVolume + row['VOLUME']
      vwap = sumTpv / sumVolume
      #Find VWAP
      #df.assign(VWAP = vwap)
      #row.assign(VWAP = vwap)
      #row[&quot;VWAP&quot;] = vwap
      df.set_value(row, 'VWAP', vwap)
      df = df.reindex(row = row)
      df[row] = df[row].astype(float)
      dayVwap = dayVwap + vwap
      
      
  
  print('Day VWAP = ', dayVwap)
  print('TPV sum = ', sumTpv)
  print('Day Volume = ', sumVolume)
  return df
  </code></pre>
  <p>And the Dataframe already has the column in it as I add it to it before I pass the df into the method. Like this</p>
  <pre><code>df[&quot;VWAP&quot;] = &quot;&quot;
  #do vwap calculation
  df = vwap2(df)
  </code></pre>
  <p>But the values either are all the same which should not be or are not written. I tried a few things but to no success.</p>
  <h2>Updates</h2>
  <p>Here is the data that I am using, I am pulling it from Google each time:</p>
  <pre><code>                       CLOSE   HIGH      LOW    OPEN  VOLUME        TP  \
   2018-05-10 22:30:00  97.3600  97.48  97.3000  97.460  371766  97.86375   
   1525991460000000000  97.2900  97.38  97.1800  97.350  116164  97.86375   
   1525991520000000000  97.3100  97.38  97.2700  97.270   68937  97.86375   
   1525991580000000000  97.3799  97.40  97.3101  97.330   46729  97.86375   
   1525991640000000000  97.2200  97.39  97.2200  97.365   64823  97.86375   
  
                            TPV        SumTPV    SumVol       VWAP  
   2018-05-10 22:30:00  3.722224e+08  1.785290e+09  18291710  97.601027  
   1525991460000000000  3.722224e+08  1.785290e+09  18291710  97.601027  
   1525991520000000000  3.722224e+08  1.785290e+09  18291710  97.601027  
   1525991580000000000  3.722224e+08  1.785290e+09  18291710  97.601027  
   1525991640000000000  3.722224e+08  1.785290e+09  18291710  97.601027  
  </code></pre>
  <p>As you can see all the calculated stuff is the same.</p>
  <p>Here is what I am using right now.</p>
  <pre><code>def vwap2(df):
  sumTpv = 0.00
  sumVolume = 0
  dayVwap = 0.00
  
  for i, row in df.iterrows():
      #Get all values from each row
      
      #Find typical price
      tp = (row['HIGH'] + row['LOW'] + row['CLOSE'] + row['OPEN']) / 4
      df['TP'] = tp
      
      tpv = tp * row['VOLUME']
      df['TPV'] = tpv
      
      sumTpv= sumTpv + tpv
      df['SumTPV'] = sumTpv
      
      sumVolume = sumVolume + row['VOLUME']
      df['SumVol'] = sumVolume
      
      vwap = sumTpv / sumVolume
      #Find VWAP
      #row.assign(VWAP = vwap)
      #row[&quot;VWAP&quot;] = vwap
      #df.set_value(row, 'VWAP', vwap)
      df[&quot;VWAP&quot;] = vwap
      dayVwap = dayVwap + vwap
      
      
  print('Day VWAP = ', dayVwap)
  print('TPV sum = ', sumTpv)
  print('Day Volume = ', sumVolume)
  return df
  </code></pre>