![](/img/trans.png)
[英]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.