[英]networkx plotted by bokeh with data from_pandas_edgelist shows wrong structure
[英]module 'networkx' has no attribute 'from_pandas_edgelist'
这是我的代码:
employee_movie_choices = pd.read_csv('Employee_Movie_Choices.txt', sep="\t")
B = nx.from_pandas_edgelist(employee_movie_choices, '#Employee', 'Movie')
并且有一个错误: AttributeError: module .networkx' has no attribute 'from_pandas_edgelist'*但是,我们可以找到.networx 的文档。networkx 具有该属性。 这是文档的链接: from_pandas_edgelist
为什么会出现这个问题?
您是否按如下方式定义别名 nx:
import networkx as nx
如果是,请尝试拨打所需的 function,如下所示:
import networkx as nx
......
......
nx.convert_matrix.from_pandas_edgelist(...)
也许你可以使用另一个from_pandas_dataframe
import pandas as pd
import networkx as nx
edges = pd.DataFrame()
# start
edges['sources'] = [1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5]
# end
edges['targets'] = [2, 4, 5, 3, 1, 2, 5, 1, 5, 1, 3, 4]
# weight
edges['weights'] = [1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1]
# build the graph
G = nx.from_pandas_dataframe(
edges,
source='sources',
target='targets',
edge_attr='weights')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.