How to create an adjacency list from an edge list efficiently
<p>I have a csv that looks like</p>

<pre><code>id1,id2
a,b
c,d
a,e
c,f
c,g
</code></pre>

<p>I read it in  to a dataframe with df = pd.read_csv("file.csv").</p>

<p>I would like to convert it to an adjacency list. That is the output should be</p>

<pre><code>a,b,e
c,d,f,g
</code></pre>

<p>I feel that df.groupby('id1') should help but variable length rows aren't suited to pandas so I am a little stuck. As my csv is large I am looking for an efficient solution however.</p>

<p>What is a good way to do this?</p>

<p>if you need CSV strings:</p>

<pre><code>In [107]: df.groupby('id1').id2.apply(lambda x: ','.join(x)).reset_index()
Out[107]:
  id1    id2
0   a    b,e
1   c  d,f,g
</code></pre>

python pandas graph