I have a CSV file that represents the adjacency matrix of a graph. However the file has as the first row the labels of the nodes and as the first column also the labels of the nodes. How can I read this file into a networkx
graph object? Is there a neat pythonic way to do it without hacking around?
My trial so far:
x = np.loadtxt('file.mtx', delimiter='\t', dtype=np.str)
row_headers = x[0,:]
col_headers = x[:,0]
A = x[1:, 1:]
A = np.array(A, dtype='int')
But of course this doesn't solve the problem since I need the labels for the nodes in the graph creation.
Example of the data:
Attribute,A,B,C
A,0,1,1
B,1,0,0
C,1,0,0
A Tab is the delimiter, not a comma tho.