Pandas GroupBy object to dataframe, store data in a comma separated file
<pre><code>interactions_df = interactions[interactions['interaction_type'].isin([1,2,3])]
</code></pre>

<p>I have interaction_df dataframe. Which when printed appears as:</p>

<pre><code>user_id item_id interaction_type    created_at
1974005 2668706 1   1444154047
2690450 405777  1   1445338496
2690450 1180447 1   1444806365
2690450 1803133 1   1440480562
2081252 405777  1   1442346826
2081252 805572  1   1441286115
732722  1266442 1   1446745768
687093  2651366 1   1445373507
</code></pre>

<p>now by simple grouping this data on 'item_id' and 'user_id' such as:</p>

<pre><code>grouped = interactions_df.groupby(['item_id', 'user_id']).count()
print(grouped)
</code></pre>

<p>I got this result:</p>

<pre><code>item_id user_id interaction_type    created_at
405777   2690450        1   1
         2081252        1   1    
805572   2081252        1   1 
1180447  2690450        1   1 
1266442  732722         1   1 
1803133  2690450        1   1
2651366  687093         1   1
2668706  1974005        1   1
</code></pre>

<p>Now what I need is to store my data in a csv file, but in this format</p>

<pre><code>item_id user_id 
405777   2690450, 2081252            
805572   2081252        
1180447  2690450         
1266442  732722          
1803133  2690450        
2651366  687093         
2668706  1974005        
</code></pre>

<p>if there is multiple users for single item then I need it in a comma separated list and just these 2 columns, no other information or counts.</p>

<p>How can I achieve this? Please suggest.</p>

<p>Thanks.</p>