-1

I have a file data.txt with the following info:

edges
1 3
2 3
3 5
4 5
5 6
node_data
1 3 4 0 0
2 4 1 0 0
3 1 6 0 0
4 2 5 0 0
5 3 5 0 0
6 1 2 0 40

I want to read the first part "edges" and crate a networkX graph and then from "node_data" to input the rest of the data in the node.

I do not need to iterate the first part only to create the graph. In the second part, I can iterate to input the data to the corresponding node

I am able to do it in separate files but I have many of them.

Any suggestion will be greatly appreciated

LuisMoncayo
  • 85
  • 1
  • 9
  • Skip the first line and then: [How to read numbers from file in Python?](https://stackoverflow.com/questions/6583573/how-to-read-numbers-from-file-in-python) – Marco Bonelli May 31 '22 at 17:06
  • Dear Marco Bonelli, it si not exactly what I mean, with the first part I have to be able to create a graph networkX, with the second I can iterate by adding the info to the nodes. Regards – LuisMoncayo May 31 '22 at 17:10
  • after skipping `edges` read each next line - if it matches `node_data` then start reading nodes, otherwise add the line to a list of edges. – Steve May 31 '22 at 17:30
  • Do you just need code to parse the file and generate two lists (1-list of edges, and 2-list of node_data)? Then with the two lists, you can then do further processing such as using the list of edges for networkX graph. – DarrylG May 31 '22 at 19:20

0 Answers0