Pandas group by into another dataframe
<p>I have a dataframe in pandas like this:</p>

<pre><code>Level_1 Level_2 Level_3 User_ID User_Flag
A       B       C       123     1
A       B       C       123     0
D       B       C       124     1
E       B       C       125     0
F       B       C       125     1
</code></pre>

<p>I need an output dataframe like this:</p>

<pre><code>Level_1 Level_2 Level_3 Size Unique_User_Size Unique_User_Size_Condition
A       B       C       2    1                1
D       B       C       1    1                1
E       B       C       1    1                0
F       B       C       1    1                1
</code></pre>

<p>So the group by level is -> Level_1,Level_2,Level_3</p>

<p>Size is number of rows by group, count(*) in sql</p>

<p>Unique_User_Size is number of distinct users in group, count(distinct user_id) in sql</p>

<p>Unique_User_Size_Condition is number of distinct users in group with User_Flag=1, count(distinct case when user_flag=1 then user_id end) in sql</p>

<p>Can someone help me how to get this?</p>