title: Python - time series alignment and "to date" functions
body: <p>I have a dataset with the following first three columns.
  Include Basket ID (unique identifier), Sale amount (dollars) and date of the transaction. I want to calculate the following column for each row of the dataset, and I would like to it in Python.</p>
  
  <p><strong>Previous Sale</strong> of the same basket (if any); <strong>Sale Count</strong> to date for current basket; <strong>Mean To Date</strong> for current basket (if available); <strong>Max To Date</strong> for current basket (if available)</p>
  
  <pre><code>Basket  Sale   Date       PrevSale SaleCount MeanToDate MaxToDate
  88      $15 3/01/2012                1      
  88      $30 11/02/2012      $15      2         $23        $30
  88      $16 16/08/2012      $30      3         $20        $30
  123     $90 18/06/2012               1      
  477     $77 19/08/2012               1      
  477     $57 11/12/2012      $77      2         $67        $77
  566     $90 6/07/2012                1      
  </code></pre>
  
  <p>I'm pretty new with Python, and I really struggle to find anything to do it in a fancy way. I've sorted the data (as above) by BasketID and Date, so I can get the previous sale in bulk by shifting forward by one for each single basket. No clue how to get the MeanToDate and MaxToDate in an efficient way apart from looping... any ideas?</p>