title: Iterating over rows of a dataframe in pandas and changing values
body: <p>My question concerns iterating through the rows of a data frame and on each row setting a field based on information in a different data frame. Sorry if this is an elementary question, but I've been through the forums without success on this. </p>
  
  <p>I have two dataframes called sample and lvlslice. I don't have a name for the index on my sample (seems to have gotten lost in the shuffle of randomly picking out some entries). For each row in sample I'm trying to sum the amount field of lvlslice entries with fbid matching my index, and put the result in my new_col.</p>
  
  <p>I can do this with some horrifically awkward for loops, making lists out of index's, etc etc. This seems like simple data manipulation, my main problem is how do I iterate over the loops of my sample data frame, and then set values based on the content of the row?</p>
  
  <p>Any help would be appreciated. I'm particularly interested in what is the right way to do a manipulation such as this, not just how to get my sums.</p>
  
  <pre><code>print(sample)
  
           purchase   new_col
  43022    True       0
  3423     True       0
  43534    True       0
  
  print(lvlslice)
  
                               fbid   other_stuff  amount
  timestamp               
  2014-01-03 00:00:10.328000   3424   stuff        320
  2014-01-03 00:00:21.419000   5557   stuff        360
  2014-01-03 00:00:22.667000   3424   stuff        7000
  ...
  </code></pre>
  
  <p>Edit: Thanks for the excellent reply, that's useful above and beyond just the question at hand.</p>