EdgeView.data#
- EdgeView.data(data=True, default=None, nbunch=None)#
Return a read-only view of edge data.
- Parameters:
- databool or edge attribute key
If
data=True, then the data view maps each edge to a dictionary containing all of its attributes. Ifdatais a key in the edge dictionary, then the data view maps each edge to its value for the keyed attribute. In this case, if the edge doesn’t have the attribute, thedefaultvalue is returned.- defaultobject, default=None
The value used when an edge does not have a specific attribute
- nbunchcontainer of nodes, optional (default=None)
Allows restriction to edges only involving certain nodes. All edges are considered by default.
- Returns:
- dataview
Returns an
EdgeDataViewfor undirected Graphs,OutEdgeDataViewfor DiGraphs,MultiEdgeDataViewfor MultiGraphs andOutMultiEdgeDataViewfor MultiDiGraphs.
See also
EdgeDataViewOutEdgeDataViewMultiEdgeDataViewOutMultiEdgeDataView
Notes
If
data=False, returns anEdgeViewwithout any edge data.Examples
>>> G = nx.Graph() >>> G.add_edges_from( ... [ ... (0, 1, {"dist": 3, "capacity": 20}), ... (1, 2, {"dist": 4}), ... (2, 0, {"dist": 5}), ... ] ... )
Accessing edge data with
data=True(the default) returns an edge data view object listing each edge with all of its attributes:>>> G.edges.data() EdgeDataView([(0, 1, {'dist': 3, 'capacity': 20}), (0, 2, {'dist': 5}), (1, 2, {'dist': 4})])
If
datarepresents a key in the edge attribute dict, a dataview listing each edge with its value for that specific key is returned:>>> G.edges.data("dist") EdgeDataView([(0, 1, 3), (0, 2, 5), (1, 2, 4)])
nbunchcan be used to limit the edges:>>> G.edges.data("dist", nbunch=[0]) EdgeDataView([(0, 1, 3), (0, 2, 5)])
If a specific key is not found in an edge attribute dict, the value specified by
defaultis used:>>> G.edges.data("capacity") EdgeDataView([(0, 1, 20), (0, 2, None), (1, 2, None)])
Note that there is no check that the
datakey is present in any of the edge attribute dictionaries:>>> G.edges.data("speed") EdgeDataView([(0, 1, None), (0, 2, None), (1, 2, None)])