turicreate.SGraph.add_vertices¶
-
SGraph.
add_vertices
(vertices, vid_field=None)¶ Add vertices to the SGraph. Vertices should be input as a list of
Vertex
objects, anSFrame
, or a pandas DataFrame. If vertices are specified by SFrame or DataFrame,vid_field
specifies which column contains the vertex ID. Remaining columns are assumed to hold additional vertex attributes. If these attributes are not already present in the graph’s vertex data, they are added, with existing vertices acquiring the valueNone
.Parameters: - vertices : Vertex | list [Vertex] | pandas.DataFrame | SFrame
Vertex data. If the vertices are in an SFrame or DataFrame, then
vid_field
specifies the column containing the vertex IDs. Additional columns are treated as vertex attributes.- vid_field : string, optional
Column in the DataFrame or SFrame to use as vertex ID. Required if vertices is an SFrame. If
vertices
is a DataFrame andvid_field
is not specified, the row index is used as vertex ID.
Returns: - out : SGraph
A new SGraph with vertices added.
Notes
- If vertices are added with indices that already exist in the graph, they are overwritten completely. All attributes for these vertices will conform to the specification in this method.
Examples
>>> from turicreate import SGraph, Vertex, SFrame >>> g = SGraph()
Add a single vertex.
>>> g = g.add_vertices(Vertex(0, attr={'breed': 'labrador'}))
Add a list of vertices.
>>> verts = [Vertex(0, attr={'breed': 'labrador'}), Vertex(1, attr={'breed': 'labrador'}), Vertex(2, attr={'breed': 'vizsla'})] >>> g = g.add_vertices(verts)
Add vertices from an SFrame.
>>> sf_vert = SFrame({'id': [0, 1, 2], 'breed':['lab', 'lab', 'vizsla']}) >>> g = g.add_vertices(sf_vert, vid_field='id')