Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.convert_matrix.to_pandas_edgelist

to_pandas_edgelist(G, source='source', target='target', nodelist=None, dtype=None, order=None)[source]

Return the graph edge list as a Pandas DataFrame.

Parameters:
  • G (graph) – The NetworkX graph used to construct the Pandas DataFrame.
  • source (str or int, optional) – A valid column name (string or iteger) for the source nodes (for the directed case).
  • target (str or int, optional) – A valid column name (string or iteger) for the target nodes (for the directed case).
  • nodelist (list, optional) – Use only nodes specified in nodelist
Returns:

df – Graph edge list

Return type:

Pandas DataFrame

Examples

>>> G = nx.Graph([('A', 'B', {'cost': 1, 'weight': 7}),
...               ('C', 'E', {'cost': 9, 'weight': 10})])
>>> df = nx.to_pandas_edgelist(G, nodelist=['A', 'C'])
>>> df
   cost source target  weight
0     1      A      B       7
1     9      C      E      10