to_pandas_edgelist(G, source='source', target='target', nodelist=None, dtype=None, order=None, edge_key=None)
The NetworkX graph used to construct the Pandas DataFrame.
A valid column name (string or integer) for the source nodes (for the directed case).
A valid column name (string or integer) for the target nodes (for the directed case).
Use only nodes specified in nodelist
Use to create the DataFrame. Data type to force. Only a single dtype is allowed. If None, infer.
An unused parameter mistakenly included in the function.
This is deprecated and will be removed in NetworkX v3.0.
A valid column name (string or integer) for the edge keys (for the multigraph case). If None, edge keys are not stored in the DataFrame.
Graph edge list
Returns the graph edge list as a Pandas DataFrame.
>>> 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
>>> G = nx.MultiGraph([('A', 'B', {'cost': 1}), ('A', 'B', {'cost': 9})])See :
... df = nx.to_pandas_edgelist(G, nodelist=['A', 'C'], edge_key='ekey')
... df[['source', 'target', 'cost', 'ekey']] source target cost ekey 0 A B 1 0 1 A B 9 1
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.convert_matrix.to_pandas_edgelist
networkx.convert_matrix.from_pandas_edgelist
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them