我无法将gml文件读入networkx。这是我使用的代码:
import networkx as nx
G = nx.read_gml('graph.gml')
我的错误回溯是:
NetworkXError Traceback (most recent call last)
<ipython-input-10-463a60088035> in <module>
1 import networkx as nx
2 import pandas as pd
----> 3 wg = nx.read_gml('Gephi Outputs/wiseguy_5_11.gml')
<C:\Users\Isaac_PC\Anaconda3\lib\site-packages\decorator.py:decorator-gen-740> in read_gml(path, label, destringizer)
~\Anaconda3\lib\site-packages\networkx\utils\decorators.py in _open_file(func_to_be_decorated, *args, **kwargs)
238 # Finally, we call the original function, making sure to close the fobj
239 try:
--> 240 result = func_to_be_decorated(*new_args, **kwargs)
241 finally:
242 if close_fobj:
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in read_gml(path, label, destringizer)
216 yield line
217
--> 218 G = parse_gml_lines(filter_lines(path), label, destringizer)
219 return G
220
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in parse_gml_lines(lines, label, destringizer)
396
397 tokens = tokenize()
--> 398 graph = parse_graph()
399
400 directed = graph.pop('directed', False)
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in parse_graph()
385
386 def parse_graph():
--> 387 curr_token, dct = parse_kv(next(tokens))
388 if curr_token[0] is not None: # EOF
389 unexpected(curr_token, 'EOF')
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in parse_kv(curr_token)
370 curr_token = next(tokens)
371 elif category == 4: # dict start
--> 372 curr_token, value = parse_dict(curr_token)
373 else:
374 unexpected(curr_token, "an int, float, string or '['")
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in parse_dict(curr_token)
380 def parse_dict(curr_token):
381 curr_token = consume(curr_token, 4, "'['") # dict start
--> 382 curr_token, dct = parse_kv(curr_token)
383 curr_token = consume(curr_token, 5, "']'") # dict end
384 return curr_token, dct
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in parse_kv(curr_token)
370 curr_token = next(tokens)
371 elif category == 4: # dict start
--> 372 curr_token, value = parse_dict(curr_token)
373 else:
374 unexpected(curr_token, "an int, float, string or '['")
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in parse_dict(curr_token)
380 def parse_dict(curr_token):
381 curr_token = consume(curr_token, 4, "'['") # dict start
--> 382 curr_token, dct = parse_kv(curr_token)
383 curr_token = consume(curr_token, 5, "']'") # dict end
384 return curr_token, dct
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in parse_kv(curr_token)
356 while curr_token[0] == 0: # keys
357 key = curr_token[1]
--> 358 curr_token = next(tokens)
359 category = curr_token[0]
360 if category == 1 or category == 2: # reals or ints
~\Anaconda3\lib\site-packages\networkx\readwrite\gml.py in tokenize()
336 else:
337 raise NetworkXError('cannot tokenize %r at (%d, %d)' %
--> 338 (line[pos:], lineno + 1, pos + 1))
339 lineno += 1
340 yield (None, None, lineno + 1, 1) # EOF
NetworkXError: cannot tokenize '-Level "3"' at (26, 14)
标记化是什么意思?我的gml有什么问题?
我承认此问题与此处的问题类似:Networkx read_gml error "networkx.exception.NetworkXError: cannot tokenize u'graph' at (3, 1)",但我不认为我的错误来自我的networkx版本,如解决方案所述。
今天早些时候,我毫不费力地读了gml文件。我对gephi中的属性表进行了一些更改-添加了一些列),并通过修改进行了重新保存,从那时起,我无法使用我的代码读取gml文件。
在gephi中进行更改似乎有所不同。那有意义吗?有什么方法可以撤消此操作或重新保存文件吗?还是有一个更好的文件可以从gephi导出而不会出现此问题?我没有得到gefx文件或graphml。到目前为止,Gml是第一个起作用的文件类型。