I have a matrix in excel that I am trying to import and convert to a numpy matrix and then graph it with networkx how would I go about doing this? I do have some code but not sure if I am going about doing this correctly.
import networkx as nx
import pandas as pd
import numpy
from numpy import genfromtxt
df=numpy.recfromcsv("Correlation_test.csv", delimiter=',', skiprows=1)
nx.Graph(df)
Thanks
This is what I have so far but, I keep getting an error saying "Input is not a correct numpy matrix or array".
If the data is a CSV file that looks like:
My graph data
0,1,1,0,0
1,0,0,1,0
1,0,0,1,1
0,1,1,0,1
0,0,1,1,0
It's simple to load and plot the resulting graph:
import numpy as np
import networkx as nx
import pylab as plt
A = np.genfromtxt("my_graph.csv",delimiter=',',skiprows=1)
G = nx.Graph(A)
nx.draw(G)
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With