title: python: using .iterrows() to create columns
body: <p>I am trying to use a loop function to create a matrix of whether a product was seen in a particular week.</p>
  
  <p>Each row in the df (representing a product) has a close_date (the date the product closed) and a week_diff (the number of weeks the product was listed).</p>
  
  <pre><code>import pandas
  mydata = [{'subid' : 'A', 'Close_date_wk': 25, 'week_diff':3},
            {'subid' : 'B', 'Close_date_wk': 26, 'week_diff':2},
            {'subid' : 'C', 'Close_date_wk': 27, 'week_diff':2},]
  df = pandas.DataFrame(mydata)
  </code></pre>
  
  <p>My goal is to see how many alternative products were listed for each product in each date_range</p>
  
  <p>I have set up the following loop:</p>
  
  <pre><code>for index, row in df.iterrows():
      i = 0
      max_range = row['Close_date_wk']    
      min_range = int(row['Close_date_wk'] - row['week_diff'])
      for i in range(min_range,max_range):
          col_head = 'job_week_'  +  str(i)
          row[col_head] = 1
  </code></pre>
  
  <p>Can you please help explain why the "row[col_head] = 1" line is neither adding a column, nor adding a value to that column for that row. </p>
  
  <p>For example, if:</p>
  
  <pre><code>row A has date range 1,2,3 
  row B has date range 2,3  
  row C has date range 3,4,5'
  </code></pre>
  
  <p>then ideally I would like to end up with</p>
  
  <pre><code>row A has 0 alternative products in week 1
            1 alternative products in week 2
            2 alternative products in week 3
  row B has 1 alternative products in week 2
            2 alternative products in week 3
  &amp;c..
  </code></pre>