title: Alternative to looping? Vectorisation, cython?
body: <p>I have a pandas dataframe something like the below:</p>
  
  <pre><code>       Total    Yr_to_Use   First_Year_Del    Del_rate 2019 2020 2021 2022 2023 etc 
  ref1    100       2020         5                 10    0    0    0    0   0
  ref2    20        2028         2                 5     0    0    0    0   0 
  ref3    30        2021         7                 16    0    0    0    0   0
  ref4    40        2025         9                 18    0    0    0    0   0
  ref5    10        2022         4                 30    0    0    0    0   0
  </code></pre>
  
  <p>The 'Total' column shows how many of a product needs to be delivered. 
  'First_yr_Del' tells you how many will be delivered in the first year. After this the delivery rate reverts to 'Del_rate' - a flat rate that can be applied each year until all products are delivered.
  The 'Year to Use' column tells you the first year column to begin delivery from.</p>
  
  <p><strong>EXAMPLE:</strong> Ref1 has 100 to deliver. It will start delivering in 2020 and will deliver 5 in the first year, and 10 each year after that until all 100 are accounted for.</p>
  
  <p>Any ideas how to go about this?</p>
  
  <p>I thought i might use something like the below to reference which columns to use in turn, but i'm not even sure if that's helpful or not as it will depend on the solution (in the proper version, base_date.year is defined as the first column in the table - 2019):</p>
  
  <pre><code>start_index_for_slice = df.columns.get_loc(base_date.year)
  end_index_for_slice = start_index_for_slice+no_yrs_to_project
  df.columns[start_index_for_slice:end_index_for_slice]
  </code></pre>
  
  <p>I'm pretty new to python and aren't sure if i'm getting ahead of myself a bit...</p>
  
  <p>The way i would think to go about it would be to use a for loop, or something using iterrows, but other posts seem to say this is a bad idea and i should be using vectorisation, cython or lambdas. Of those 3 i've only managed a very simple lambda so far. The others are a bit of a mystery to me since the solution seems to suggest doing one action after another until complete.</p>
  
  <p>Any and all help appreciated!</p>
  
  <p>Thanks</p>
  
  <p>EDIT: Example expected output below (I edited some of the dates so you can better see the logic):</p>
  
  <pre><code>       Total    Yr_to_Use   First_Year_Del Del_rate 2019 2020 2021 2022 2023etc 
  ref1    100       2020         5              10    0    5    10    10   10
  ref2    20        2021         2              5     0    0    2     5    5 
  ref3    30        2021         7              16    0    0    7     16   7
  ref4    40        2019         9              18    9    18   13    0    0
  ref5    10        2020         4              30    0    4    6     0    0
  </code></pre>