from_pandas_adjacency(df, create_using=None)
The Pandas DataFrame is interpreted as an adjacency matrix for the graph.
For directed graphs, explicitly mention create_using=nx.DiGraph, and entry i,j of df corresponds to an edge from i to j.
If :None:None:`df`
has a single data type for each entry it will be converted to an appropriate Python data type.
If :None:None:`df`
has a user-specified compound data type the names of the data fields will be used as attribute keys in the resulting NetworkX graph.
An adjacency matrix representation of a graph
Graph type to create. If graph instance, then cleared before populated.
Returns a graph from Pandas DataFrame.
Simple integer weights on edges:
>>> import pandas as pd
... pd.options.display.max_columns = 20
... df = pd.DataFrame([[1, 1], [2, 1]])
... df 0 1 0 1 1 1 2 1
>>> G = nx.from_pandas_adjacency(df)See :
... G.name = "Graph from pandas adjacency matrix"
... print(nx.info(G)) Graph named 'Graph from pandas adjacency matrix' with 2 nodes and 3 edges
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.convert_matrix.from_pandas_adjacency
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