turicreate.SGraph.add_edges

SGraph.add_edges(edges, src_field=None, dst_field=None)

Add edges to the SGraph. Edges should be input as a list of Edge objects, an SFrame, or a Pandas DataFrame. If the new edges are in an SFrame or DataFrame, then src_field and dst_field are required to specify the columns that contain the source and destination vertex IDs; additional columns are treated as edge attributes. If these attributes are not already present in the graph’s edge data, they are added, with existing edges acquiring the value None.

Parameters:
edges : Edge | list [Edge] | pandas.DataFrame | SFrame

Edge data. If the edges are in an SFrame or DataFrame, then src_field and dst_field are required to specify the columns that contain the source and destination vertex IDs. Additional columns are treated as edge attributes.

src_field : string, optional

Column in the SFrame or DataFrame to use as source vertex IDs. Not required if edges is a list.

dst_field : string, optional

Column in the SFrame or Pandas DataFrame to use as destination vertex IDs. Not required if edges is a list.

Returns:
out : SGraph

A new SGraph with edges added.

See also

Edge, SFrame, add_vertices

Notes

  • If an edge is added whose source and destination IDs match edges that already exist in the graph, a new edge is added to the graph. This contrasts with add_vertices(), which overwrites existing vertices.

Examples

>>> from turicreate import SGraph, Vertex, Edge, SFrame
>>> g = SGraph()
>>> verts = [Vertex(0, attr={'breed': 'labrador'}),
             Vertex(1, attr={'breed': 'labrador'}),
             Vertex(2, attr={'breed': 'vizsla'})]
>>> g = g.add_vertices(verts)

Add a single edge.

>>> g = g.add_edges(Edge(1, 2))

Add a list of edges.

>>> g = g.add_edges([Edge(0, 2), Edge(1, 2)])

Add edges from an SFrame.

>>> sf_edge = SFrame({'source': [0, 1], 'dest': [2, 2]})
>>> g = g.add_edges(sf_edge, src_field='source', dst_field='dest')