Use pandas groupby.size() results for arithmetical operation
<p>I got the following problem which I got stuck on and unfortunately cannot resolve by myself or by similar questions that I found on stackoverflow.</p>

<p>To keep it simple, I'll give a short example of my problem:</p>

<p>I got a Dataframe with several columns and one column that indicates the ID of a user. It might happen that the same user has several entries in this data frame:</p>

<pre><code>|   |  userID   |      col2      | col3  |
+---+-----------+----------------+-------+
| 1 | 1         | a              |     b |
| 2 | 1         | c              |     d |
| 3 | 2         | a              |     a |
| 4 | 3         | d              |     e |
</code></pre>

<p>Something like this. Now I want to known the number of rows that belongs to a certain userID. For this operation I tried to use <code>df.groupby('userID').size()</code> which in return I want to use for another simple calculation, like division whatsover. 
But as I try to save the results of the calculation in a seperate column, I keep getting NaN values. </p>

<p>Is there a way to solve this so that I get the result of the calculations in a seperate column?</p>

<p>Thanks for your help!</p>

<p>edit//</p>

<p>To make clear, how my output should look like. The upper dataframe is my main data frame so to say. Besides this frame I got a second frame looking like this:</p>

<pre><code>|   |  userID   |      value     | value/appearances  |
+---+-----------+----------------+-------+
| 1 | 1         | 10             |     10 / 2 = 5     |
| 3 | 2         | 20             |     20 / 1 = 20    |
| 4 | 3         | 30             |     30 / 1 = 30    |
</code></pre>

<p>So I basically want in the column 'value/appearances' to have the result of the number in the value column divided by the number of appearances of this certain user in the main dataframe. For user with ID=1 this would be 10/2, as this user has a value of 10 and has 2 rows in the main dataframe.
I hope this makes it a bit clearer.</p>