简体   繁体   中英

Equivalent of R igraph graph_from_data_frame() function in Python igraph?

Is there an equivalent of this igraph R function in Python igraph?

graph_from_data_frame(d, directed = TRUE, vertices = NULL)

This function creates an igraph graph from one or two data frames containing the (symbolic) edge list and edge/vertex attributes.

Python does not have data frames so there is no direct equivalent. The closest equivalent could be Graph.DictList , which creates a graph from a list of dictionaries, or Graph.TupleList , which is the same for a list of tuples.

Right now you can use this:

from igraph import Graph
g = Graph.DataFrame(edges, directed=False, vertices=vertices, use_vids=False)

where "edges" is the dataframe with the edges, vertices are the names that will be used in each vertex, and use_vids if you want to assign indexes to name the edges instead of using the "vertices" data

https://igraph.org/python/api/0.9.7/igraph.Graph.html#DataFrame

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM