title: Pandas: for each row in a DataFrame, count the number of rows matching a condition
body: <p>I have a DataFrame for which I want to calculate, for each row, how many other rows match a given condition (e.g. number of rows that have value in column C less than the value for this row). Iterating through each row is too slow (I have ~1B rows), especially when the columns dtype is a datetime, but this is the way it could be run on a DataFrame df with a column labeled C:</p>
  
  <pre><code>df['newcol'] = 0
  for row in df.itertuples():
      df.loc[row.Index, 'newcol'] = len(df[df.C &lt; row.C])
  </code></pre>
  
  <p>Is there a way to vectorize this?</p>
  
  <p>Thanks!</p>