load_graph_from_csv

load_graph_from_csv#

graph_tool.load_graph_from_csv(file_name, directed=False, eprop_types=None, eprop_names=None, hashed=True, hash_type='string', skip_first=False, strip_whitespace=True, ecols=(0, 1), csv_options={'delimiter': ',', 'quotechar': '"'})[source]#

Load a graph from a csv file containing a list of edges and edge properties.

Parameters:
file_namestr or file-like object

File in :mod:csv format, with edges given in each row.

directedbool (optional, default: False)

Whether or not the graph is directed.

eprop_typeslist of str (optional, default: None)

List of edge property types to be read from remaining columns (if this is None, all properties will be of type string.

eprop_nameslist of str (optional, default: None)

List of edge property names to be used for the remaining columns (if this is None, and skip_first is True their values will be obtained from the first line, otherwise they will be called c1, c2, ...).

hashedbool (optional, default: True)

If True the vertex values in the edge list are not assumed to correspond to vertex indices directly. In this case they will be mapped to vertex indices according to the order in which they are encountered, and a vertex property map with the vertex values is returned.

hash_typestr (optional, default: string)

If hashed == True, this will determined the type of the vertex values. It can be any property map value type (see PropertyMap).

skip_firstbool (optional, default: False)

If True the first line of the file will be skipped.

strip_whitespacebool (optional, default: True)

If True whitespace will be striped from the start and end of values, before processing them.

ecolspair of int (optional, default: (0,1))

Line columns used as source and target for the edges.

csv_optionsdict (optional, default: {"delimiter": ",", "quotechar": '"'})

Options to be passed to the csv.reader() parser.

Returns:
gGraph

The loaded graph. It will contain additional columns in the file as internal edge property maps. If hashed == True, it will also contain an internal vertex property map with the vertex names.