Warning
This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
Edge List¶
Read and write NetworkX graphs as edge lists.
The multi-line adjacency list format is useful for graphs with nodes that can be meaningfully represented as strings. With the edgelist format simple edge data can be stored but node or graph data is not. There is no way of representing isolated nodes unless the node has a self-loop edge.
Format¶
You can read or write three formats of edge lists with these functions.
Node pairs with no data:
1 2
Python dictionary as data:
1 2 {'weight':7, 'color':'green'}
Arbitrary data:
1 2 7 green
read_edgelist(path[, comments, delimiter, ...]) | Read a graph from a list of edges. |
write_edgelist(G, path[, comments, ...]) | Write graph as a list of edges. |
read_weighted_edgelist(path[, comments, ...]) | Read a graph as list of edges with numeric weights. |
write_weighted_edgelist(G, path[, comments, ...]) | Write graph G as a list of edges with numeric weights. |
generate_edgelist(G[, delimiter, data]) | Generate a single line of the graph G in edge list format. |
parse_edgelist(lines[, comments, delimiter, ...]) | Parse lines of an edge list representation of a graph. |