Here, mentions the use of a second Dataframe to add vertex attributes, but I cannot understand what it is saying.
From pandas DataFrame(s)
A common practice is to store edges in a pandas.DataFrame, where the two first columns are the source and target vertex ids, and any additional column indicates edge attributes. You can generate a graph via
Graph.DataFrame()
:g = Graph.DataFrame(edges, directed=False)
It is possible to set vertex attributes at the same time via a separate DataFrame. The first column is assumed to contain all vertex ids (including any vertices without edges) and any additional columns are vertex attributes:
g = Graph.DataFrame(edges, directed=False, vertices=vertices)
Something like:
g = ig.Graph.DataFrame(df, vertices=df2)
nor does
g = ig.Graph.DataFrame(df, df2)
nor
g = ig.Graph.DataFrame(df, directed=False, vertices=df2)
Seems not work. I cannot colorize based on the attribute, and printing all
print(ig.vertex_attr(g))
finds Attribute does not exist
Tried some more:
os.chdir("C:/Users/bizo2/Desktop")
df = pd.read_excel("edgelist5.xlsx")
df2 = pd.read_excel("Book4.xlsx")
g = ig.Graph.DataFrame(df)
visual_style = {}
visual_style["vertex_size"] = 20
visual_style["vertex_label"] = g.vs["name"]
g.vs["RTD"] = df2['RTD'].values.tolist()
Book4 is literally just a column of values for attribute that aligns with the order of df, even when there are multiple vertices. From here