[Python] Plot a graph from .txt file in python-igraph

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to load data from a text file. The .txt file contains 4 columns space separated. The structure of the .txt file is defined below

    Id | Category | Related Id 1 | Related Id 2


    The data looks like this

    SQI9xPF9rdk Gadgets & Games SQI9xPF9rdk U0raaoN6I6M
    4q5jSGOcZb8 Gadgets & Games SQI9xPF9rdk U0raaoN6I6M


    The 1st, 3rd & 4th columns are related i.e the nodes will be 1st, 3rd, 4th columns respectively with edges being the links between them.

    I'm trying to read the .txt file into igraph by first populating an adjacency matrix and then loading it in igraph, but I'm getting the following error:


    Traceback (most recent call last):

    File "C:/Users/Lucy/PycharmProjects/Project/dataClean.py", line 9, in
    g=igraph.Graph.adj(m,mode="undirected")
    AttributeError: type object 'Graph' has no attribute 'adj'
    ​

    Python code:

    import igraph
    import numpy as np
    F = open('1.txt','r')
    m=np.matrix(F)
    g=igraph.Graph.adj(m,mode="undirected")


    I can't understand what I'm doing wrong. Please help

    Continue reading...

Compartilhe esta Página