title: Making edge list from Pandas Data frame by matching row values and put into edgelist
body: <p>I'm new to Python and I'm trying to run a community detection algorithm using a dataset stored in a pandas dataframe, to do this I need to make an edgelist from this dataset to be put into a graph. I need this edgelist to consist of rows with matching column value. 
  The dataset consists of 19 columns and over 2000 rows I need to make edges between each column row that have matching values. 
  For example if the dataset were</p>
  
  <pre><code>id   col1 col2 col3 
   1    12    10   20
   2    14    10   19
   3    12    10   9 
  </code></pre>
  
  <p>Then there would be the following edges</p>
  
  <pre><code>row1 col1, row2 col1
  row1 col2, row2 col2
  row1 col2, row3 col2
  row2 col2, row3 col2
  </code></pre>
  
  <p>I've tried a couple of ways but none seem to work quite the way I want the closest I got was using the following code: </p>
  
  <pre><code>#define edges as column rows that have matching data
  edges = set()
  for col in dataset:
      for _, data in dataset.groupby(col):
          edges.update(itertools.combinations(data.index, 2)) 
  
  #create empty graph
  G = nx.Graph()
  #add index number as node to graph
  G.add_nodes_from(dataset.index)
  #add edges created 
  G.add_edges_from(edges)
  
  #uses community library to work define best partition that maximise modularity (Louvain Algorithm)
  partition= community.best_partition(G)
  
  #create graph from the results of the partition
  size = float(len(set(partition.values())))
  pos = nx.spring_layout(G)
  count = 0.
  for com in set(partition.values()) :
      count = count + 1.
      list_nodes = [nodes for nodes in partition.keys()
                                  if partition[nodes] == com]
      nx.draw_networkx_nodes(G, pos, list_nodes, node_size = 20, cmap=plt.cm.RdYlBu,
                                  node_color=list(partition.values()))
  plt.show()
  </code></pre>