I am trying to calculate a pagerank for a buyer/seller network. A buyer could be seller too, meaning A could sell $100 worth of stuff to B, and B could sell $20 worth of (other) stuff to A. So I am using DiGraph for the network, and the weight is the $ value.
My question is, the below two scripts, either with or without edge_attr, yield the exact same pagerank values.
So am I missing anything here?
Thank you very much for your time.
import pandas as pd
import networkx as nx
df =pd.DataFrame({'Seller':['A1','B1', 'A2','A2','B2', 'B2'],
'Buyer':['B1','A1','B1','B2','A2', 'B2'],
'Value':[10,20,30,40,50, 5]})
g1 = nx.from_pandas_edgelist(df, 'Seller', "Buyer", create_using=nx.DiGraph())
pagerank_g1 = nx.pagerank(g1)
pagerank_g1=sorted(pagerank_g1.items(),key=lambda v:(v[1],v[0]),reverse=True)
print(' no weight, pagerank_g1', pagerank_g1)
g2=nx.from_pandas_edgelist(df, 'Seller', "Buyer", create_using=nx.DiGraph(), edge_attr='Value')
pagerank_g2 = nx.pagerank(g2)
pagerank_g2=sorted(pagerank_g2.items(),key=lambda v:(v[1],v[0]),reverse=True)
print('with weight, pagerank_g2', pagerank_g2) }
That's because the default
weightname inpagerankisweightwhile yours isValue.So either use :
Or rename the column and the edge attribute's name :
Output :