networkx.convert_matrix.to_pandas_edgelist¶
-
to_pandas_edgelist
(G, source='source', target='target', nodelist=None, dtype=None, order=None)[source]¶ Returns 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 integer) for the source nodes (for the directed case).
target (str or int, optional) – A valid column name (string or integer) 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[['source', 'target', 'cost', 'weight']] source target cost weight 0 A B 1 7 1 C E 9 10