How to import csv format Adjacency Matrix hashtag network in CSV file?

Tags: , , ,

My hashtag co-occurrence network is stored as an adjacency matrix in CSV format like this.


Then I use this page as a reference Plot NetworkX Graph from Adjacency Matrix in CSV file

I want to import this matrix into networkx and I tried this:

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from numpy import genfromtxt
import numpy as np

mydata = genfromtxt('data.csv', delimiter=',')

But I only got this:


[nan nan]
<class 'numpy.ndarray'>

How can I import my data correctly, I want to use the python pipeline to calculate degree centrality of each nodes in the network.And importing is the first step.


The numpy.genfromtxt function has an optional argument called comments that by default is set to "#".

comments : str, optional
    The character used to indicate the start of a comment.
    All the characters occurring on a line after a comment are discarded

In other words numpy thinks your entire file contains comments and empty rows. You will have to either rename your row and column identifiers or you have to set the comments argument to some other value such as "*"

Source: stackoverflow