0

I want to perform personlized pagerank (ppr) in python using networkx as explained here

I have a dataframe that contains the edgelist between two nodes i and j

df
     i     j
0    A     B
1    B     C
2    B     A
3    C     A
4    C     B

and for each node I have a label 0 or 1.

dfN 
      Node  Label
0      A     0
1      B     1
2      C     0

I created the network

import networkx as nx
g = nx.from_pandas_edgelist(df, 'A', 'B')

Now I want to run the ppr

ppr1 = nx.pagerank(g,personalization={A:0, B:1, C:0})

How can I create the dict {A:0, B:1, C:0} directly from dfN?

emax
  • 6,965
  • 19
  • 74
  • 141

1 Answers1

2

You can use the in-built method to_dict:

pd.Series([0, 1, 1, 0], index=[0, 1, 2,3]).to_dict()
Out[39]: {0: 0, 1: 1, 2: 1, 3: 0}
FLab
  • 7,136
  • 5
  • 36
  • 69