title: Cumulative count at group level with boolean indexing in Pandas
body: <p>I'm developing an answer to <a href="https://stackoverflow.com/questions/66932614/cumulative-count-at-a-group-level-python">this</a> question that just uses boolean indexing rather than <code>cumcount</code>. The intended output is a column <code>total_paid_invoices</code> that — for each company — counts the number of reach voices paid prior (prior in terms of datetime) to each record.</p>
  <pre><code>    company invoice date
  0   A   1234    20120201
  1   A   1134    20120201
  2   A   1011    20120201
  3   A   1123    20121004
  4   A   1111    20121004
  5   A   1224    20121105
  6   B   1156    20120403
  7   B   2345    20120504
  8   B   4567    20120504
  9   B   8796    20120606
  </code></pre>
  <p>I'm handling the company groups in a for loop instead of in a groupby:</p>
  <pre><code>for company in df.company.unique():
      df['total_paid_invoices'] = df.date.apply(
          lambda x: df.loc[(df.date&lt;x)&amp;(df.company==company)].shape[0]
      )
  </code></pre>
  <p>However, the output is incorrect on line five (the value should be <code>5</code>):</p>
  <pre><code>    company invoice date    total_paid_invoices
  0   A   1234    2012-02-01  0
  1   A   1134    2012-02-01  0
  2   A   1011    2012-02-01  0
  3   A   1123    2012-10-04  4
  4   A   1111    2012-10-04  4
  5   A   1224    2012-11-05  4
  </code></pre>
  <p>Here's why I'm asking this question: When I do the operation just on the date at line five</p>
  <pre><code>df.loc[(df.date&lt;df.date.iloc[5])&amp;(df.company=='A')].shape[0]
  </code></pre>
  <p>the output is <code>5</code>. Why is this not making it into the output dataframe while the rest of the values we see in the sample data are being processed correctly?</p>