You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import pandas as pd
# Read CSV files
nodes_df = pd.read_csv('nodes.csv')
edges_df = pd.read_csv('edges.csv')
# Create a new graph widget
w = GraphWidget()
# Add nodes with all attributes
w.nodes = []
for _, row in nodes_df.iterrows():
node_attrs = row.to_dict()
node_id = node_attrs.pop('id') # Assuming 'id' is the column for node identifiers
w.nodes.append({
"id": node_id,
"properties": node_attrs
})
# Add edges with all attributes
w.edges = []
for _, row in edges_df.iterrows():
edge_attrs = row.to_dict()
edge_id = edge_attrs.pop('id', None) # Assuming 'id' is the column for edge identifiers
source = edge_attrs.pop('source') # Assuming 'source' is the column for edge source
target = edge_attrs.pop('target') # Assuming 'target' is the column for edge target
w.edges.append({
"id": edge_id if edge_id is not None else f"{source}-{target}",
"start": source,
"end": target,
"properties": edge_attrs
})
# Set the graph as directed (you can change this if your graph is undirected)
w.directed = True
# Display the graph
display(w)
Thanks a lot for the code. I'll give it a try very soon.
I'll release a content on yWorks/yfiles-jupyter-graphs next week, with the graphml import, including a blog post and a video
β About
In various graph dataviz tools (like Gephi) it is very common to import files to create a graph with
csv
:nodes.csv
edges.csv
The main idea would to make it easy to do the same on yFiles.
π‘ Feature request
β³ Workaround
As a workaround I'm using the
graphml
import featureThe text was updated successfully, but these errors were encountered: