networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersBackRef
from_pandas_adjacency(df, create_using=None)

The Pandas DataFrame is interpreted as an adjacency matrix for the graph.

Notes

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.

Parameters

df : Pandas DataFrame

An adjacency matrix representation of a graph

create_using : NetworkX graph constructor, optional (default=nx.Graph)

Graph type to create. If graph instance, then cleared before populated.

Returns a graph from Pandas DataFrame.

See Also

to_pandas_adjacency

Examples

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)
... G.name = "Graph from pandas adjacency matrix"
... print(nx.info(G)) Graph named 'Graph from pandas adjacency matrix' with 2 nodes and 3 edges
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.convert_matrix.from_pandas_adjacency

Local connectivity graph

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


GitHub : /networkx/convert_matrix.py#157
type: <class 'function'>
Commit: