1

I am new user of python and networks, I have trouble to read some data from .gml file My IDE is Spyder,Anaconda,and OS is macOS is I follow the instruction online ,here is my code ,here is the Dataset

import networkx as nx
import matplotlib.pyplot as plt 

G = nx.Graph()
G = nx.read_gml('karate.gml')

print (nx.info(G))

then the complier shows "node #0 has no 'label' attribute". How could it happens

ShaoyuPei
  • 199
  • 9
  • Networkx [have](https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.generators.social.karate_club_graph.html) the karate graph. Try: `nx.karate_club_graph()` – Lucas Sep 13 '18 at 04:33
  • @Lucas I just request by reading third party data by my instructor :( – ShaoyuPei Sep 13 '18 at 04:36
  • 2
    I think we'll need to see karate.gml before we can answer the question. – Joel Sep 13 '18 at 07:00
  • @Joel hi Joel I already update – ShaoyuPei Sep 13 '18 at 15:06
  • hmm, this is the `karate.gml` from Mark Newman's webpage... I see the same error. I wonder if this is a bug in networkx, perhaps something introduced when it upgraded to version 2.0? You could maybe try networkx 1.11. – Joel Sep 13 '18 at 15:28
  • https://github.com/networkx/networkx/issues/3157 – Joel Sep 15 '18 at 04:38
  • repeat question, go through this link for solution https://stackoverflow.com/questions/39200898/reading-a-gml-file-with-networkx-python-without-labels-for-the-nodes – user3322017 May 29 '19 at 11:38

1 Answers1

7

If you are using that popular karate.gml datasets, try the code below:

G = nx.read_gml('karate.gml', label = 'id')
jlewkovich
  • 2,725
  • 2
  • 35
  • 49
Mike Xie
  • 71
  • 1
  • 3