擅长:python、mysql、java
<p>下面是networkx的一个解决方案。你知道吗</p>
<pre><code>import networkx as nx
a = np.where(df.T, df.index, '').sum(axis=1)
g = [list(x) for x in a if len(x) > 1]
G = nx.Graph(g)
list(nx.connected_components(G))
[{'B', 'D', 'E'}, {'A', 'C'}]
</code></pre>