Hi everyone I want to read the edge list from a csv file and create a graph with networkx to calculate the betweenness centrality with python. My code is:
import pandas as pd
import networkx as nx
df = pd.read_csv('edges1.csv')
Graphtype = nx.Graph()
G = nx.from_pandas_edgelist(df, edge_attr='genre_ids', create_using=Graphtype)
centrality = nx.betweenness_centrality(G, normalize=False)
print(centrality)
edges1.csv have 97180 row:
Surce,Target,genre_ids
Avatar,Violent Night,18
Harry Potter,The Woman King,20
Happy Feet, Froze,23
so on....
My code give me error: KeyError: 'source'. How can i do?
Surce,Target,genre_idsin the csv you should putsource,target,genre_ids, so with anoin source and lower case.from_pandas_edgelistrequires validsourcecolumn, fix your file header