简体   繁体   中英

module 'networkx' has no attribute 'from_pandas_edgelist'

here is my code:

employee_movie_choices = pd.read_csv('Employee_Movie_Choices.txt', sep="\t")
B = nx.from_pandas_edgelist(employee_movie_choices, '#Employee', 'Movie')

and there is an error: AttributeError: module .networkx' has no attribute 'from_pandas_edgelist'* however, this the documents of.networx we could find.networkx has the attribute. here is the link of the documents: from_pandas_edgelist

why did this question happen?

Are you defining the alias nx as follows:

import networkx as nx

If yes, try calling the required function as follows:

import networkx as nx 
......
......
nx.convert_matrix.from_pandas_edgelist(...)

maybe you can use anothor function 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM