Reputation: 161
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?
Upvotes: 1
Views: 1384
Reputation: 1
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')
Upvotes: 0
Reputation: 1413
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(...)
Upvotes: 2