pythongraphigraph

Not able to read .txt file in iGraph python


I'm trying to read a text file containing space separated columns using python's python-igraph library. I'm following the documentation but still getting the following error.

Traceback (most recent call last):
File "C:/Users/Lucy/PycharmProjects/CS286Project/dataClean.py", line 3, in 
<module>
read_graph= Graph.Read_Ncol('1.txt', directed=True)
NameError: name 'Graph' is not defined

Python code..

  import igraph
  read_graph = Graph.Read_Ncol('1.txt', directed=True)

.txt file

 72QMMSWgOns    boBreak 755 Comedy  35  604 3.91    11  3   hQ-xsBZ_Nqo
 vVa0VC9o3MQ    sagopakajmerat  728 Film & Animation    192 266 4   4   4   bnC17Mr010k

Since the spacing between columns is uneven, is that what is causing this error?

Edit 1:

After using the solution provided by @Gwendal Grelier I get the following error

  read_graph = igraph.Graph.Read_Ncol('1.txt', directed=True)
   igraph._igraph.InternalError: Error at src\foreign.c:243: Parse error in NCOL file, line 1 (syntax error, unexpected ALNUM, expecting NEWLINE), Parse error

Solution

  • As I said in the comment, you are missing the module name in the declaration of your Graph() method !

    import igraph
    read_graph = igraph.Graph.Read_Ncol('1.txt', directed=True)
    

    Should do the trick !