title: Count number of child records in dataframe
body: <p>I have a pandas.DataFrame with the columns <code>parentId</code> and <code>id_x</code>. I am now trying to create a new column, which displays the number of related child(<code>id_x</code>) in  the parent entry. The related SQL query for one entry (id) would be <code>SELECT COUNT(*) AS amount FROM node WHERE parentId=&quot;1234qwer&quot;</code>. Is there a way to apply this for every row in a pandas dataframe? In the dataframe it could also be possible that a parent is a child of a higher parent.</p>
  <p>EDIT:</p>
  <p>Here is a sample of the data</p>
  <pre><code>df[[&quot;parentId&quot;, &quot;id_x&quot;]].head(4)
  
  |               parentId               |                 id_x                 |
  | ------------------------------------ | ------------------------------------ |
  | 071cb2c2-d1be-4154-b6c7-a29728357ef3 | a061e7d7-95d2-4812-87c1-24ec24fc2dd2 |
  | a061e7d7-95d2-4812-87c1-24ec24fc2dd2 | d2b62e36-b243-43ac-8e45-ed3f269d50b2 |
  |                 None                 | 071cb2c2-d1be-4154-b6c7-a29728357ef3 |
  | 071cb2c2-d1be-4154-b6c7-a29728357ef3 | a0e97b37-b9a1-4304-9769-b8c48cd9f184 |
  </code></pre>
  <p>There are n <code>parentId</code> that can match the <code>id_x</code>. I now want to create a new column that counts/displays the number of <code>parentId</code> that match a specific <code>id_x</code>.</p>
  <p>The result should look like the following:</p>
  <pre><code> df[[&quot;parentId&quot;, &quot;id_x&quot;, &quot;Amount&quot;]].head(4)
  
  |               parentId               |                 id_x                 | Amount |
  | ------------------------------------ | ------------------------------------ | ------ |
  | 071cb2c2-d1be-4154-b6c7-a29728357ef3 | a061e7d7-95d2-4812-87c1-24ec24fc2dd2 | 1      |
  | a061e7d7-95d2-4812-87c1-24ec24fc2dd2 | d2b62e36-b243-43ac-8e45-ed3f269d50b2 | 0      |
  |                 None                 | 071cb2c2-d1be-4154-b6c7-a29728357ef3 | 2      |
  | 071cb2c2-d1be-4154-b6c7-a29728357ef3 | a0e97b37-b9a1-4304-9769-b8c48cd9f184 | 0      |
  </code></pre>