I have (x,y) coordinates and edge connections in a csv file. I want to plot my graph using the (x,y) coordinates and edge connections using csv import. Here Iam attaching the sample csv table format and my expected output?
Asked
Active
Viewed 58 times
1 Answers
0
You can start by using this to make the inputs from your .csv
:
import csv
from ast import literal_eval
with open("file.csv", "r") as f:
reader = csv.DictReader(f, delimiter=",") # <-- adjust the sep if needed
rows = list(reader)
points = [literal_eval(row["xy"]) for row in rows]
edges = [(literal_eval(row["v1v2"]) + (int(row["w"]),)) for row in rows]
Then you can use/readapt @Sparky05's answer.
Output :

Timeless
- 22,580
- 4
- 12
- 30
-
What would be the code if we don't have node id's, only coordinates as edge connections? Instead of node id's, coordinates to coordinates as v1v2 in the previously mentioned table. for eg. v1v2 as ((1,10), (8,10)), ((8,10), (10,8)), ((10,8), (7,4)), ((1,10), (7,4)), ((7,4), (3,1)). – Vishnu M May 01 '23 at 12:20