title: How to get an accumulative counting of rows in a data frame?
body: <p>I have a data frame (called <code>u</code>) in which one of the columns (called <code>dates</code>) contains dates. Now I would like to generate another data frame which containing all the dates between the minimal and maximal dates from the <code>u</code> table (each row correspond to a date). In the new data frame I also would like to have a column that indicated how many rows from the first table have a smaller date.</p>
  
  <p>For example of the first table is like that:</p>
  
  <pre><code>| a | 2015-01-01 |
  | b | 2015-01-01 |
  | c | 2015-01-03 |
  | d | 2015-01-04 |
  </code></pre>
  
  <p>Then the second data frame has to be like that:</p>
  
  <pre><code>| 2015-01-01 | 0 |
  | 2015-01-02 | 2 |
  | 2015-01-03 | 2 |
  | 2015-01-04 | 3 |
  </code></pre>
  
  <p>I wrote a code that does exactly what I need, but it is extremely slow and not elegant. This is what I have:</p>
  
  <pre><code>min_date = u.dates.min()
  max_date = u.dates.max()
  dates = []
  date = min_date
  while True:
      dates.append(date)
      if date == max_date:
          break
      date = date + datetime.timedelta(days=1)
  
  date2n = {}
  for date in dates:
      n = len(u[u.dates &lt; date]) 
      date2n[date] = n
  </code></pre>
  
  <p>Is there a better way to do what I am trying to do?</p>