I’m trying to create 3 graph layers from different dataframes to then cluster using leidenalg.
I have three edge dfs which have 3 columns source, target, weight and 1 node df structured nodeId, nodeName.
The nodes are the same for each of the dataframes but not all nodes have connections in each layer. So not all nodes appear in every df.
When i then cluster using Leidenalg i get this error:
ValueError: Number of nodes are not equal for all graphs.
which i think is because the nodes without connections are not currently in the igraph graphs. How would you add these in?
When creating a graph based on an edge dataframe, but want to ensure you have the same vertices in all graphs, you have to specify the vertices as well.
In the Graph.DataFrame you can specify separately the edges and the vertices, see igraph.Graph for more details.
Alternatively, you can simply concatenate all edge dataframes, but add one column (e.g. layer), and create one graph with all edges. Based on this single graph, you can then construct different subgraphs for the different layers using subgraph_edges.