title: Pandas Expanding Mean with Group By and before current row date
body: <p>I have a Pandas dataframe as follows</p>
  
  <pre><code>df = pd.DataFrame([['John', '1/1/2017','10'],
                     ['John', '2/2/2017','15'],
                     ['John', '2/2/2017','20'],
                     ['John', '3/3/2017','30'],
                     ['Sue', '1/1/2017','10'],
                     ['Sue', '2/2/2017','15'],
                     ['Sue', '3/2/2017','20'],
                     ['Sue', '3/3/2017','7'],
                     ['Sue', '4/4/2017','20']
                    ],
                     columns=['Customer', 'Deposit_Date','DPD'])
  </code></pre>
  
  <p>. What is the best way to calculate the PreviousMean column in the screen shot below? </p>
  
  <p>The column is the year to date average of DPD for that customer. I.e. Includes all DPDs up to but not including rows that match the current <strong>deposit date</strong>. If no previous records existed then it's null or 0.</p>
  
  <p><strong>Screenshot:</strong>
  <a href="https://i.stack.imgur.com/08ZBF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/08ZBF.png" alt="enter image description here"></a></p>
  
  <p><strong>Notes:</strong></p>
  
  <ul>
  <li>the data is grouped by Customer Name and expanding over Deposit Dates</li>
  <li>within each group, the expanding mean is calculated using only values from the previous rows.</li>
  <li>at the start of each new customer the mean is 0 or alternatively null as there are no previous records on which to form the mean</li>
  <li>the data frame is ordered by Customer Name and Deposit_Date</li>
  </ul>