Python: how to merge a networkx graph with a dataframe?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a networkx graph g that I created from a pandas dataframe df and I saved.



df
A B
0 359 278
1 576 437
2 329 177
3 329 278

g = pd.from_edgelist(df, 'A', 'B')


I saved it as a pickle



nx.write_gpickle(g, 'myGraph.gz')


I am now reading this graph for another project



g = nx.read_pickle('myGraph.gz')


I now have a datframe containing the information of some of the nodes in g.



df1
Node Y
0 359 0
1 576 1
2 329 1
3 278 0
4 100 0
5 437 1


I want to use the information df.Y for the performing the personalized pagerank only for the nodes in common between df and g. After the merge I would like to have something like the following.



d = pd.Series(df1['Y'], index=df1.index).to_dict()
ppr = nx.pagerank(g, alpha=0.85, personalization=d)









share|improve this question





























    0















    I have a networkx graph g that I created from a pandas dataframe df and I saved.



    df
    A B
    0 359 278
    1 576 437
    2 329 177
    3 329 278

    g = pd.from_edgelist(df, 'A', 'B')


    I saved it as a pickle



    nx.write_gpickle(g, 'myGraph.gz')


    I am now reading this graph for another project



    g = nx.read_pickle('myGraph.gz')


    I now have a datframe containing the information of some of the nodes in g.



    df1
    Node Y
    0 359 0
    1 576 1
    2 329 1
    3 278 0
    4 100 0
    5 437 1


    I want to use the information df.Y for the performing the personalized pagerank only for the nodes in common between df and g. After the merge I would like to have something like the following.



    d = pd.Series(df1['Y'], index=df1.index).to_dict()
    ppr = nx.pagerank(g, alpha=0.85, personalization=d)









    share|improve this question

























      0












      0








      0








      I have a networkx graph g that I created from a pandas dataframe df and I saved.



      df
      A B
      0 359 278
      1 576 437
      2 329 177
      3 329 278

      g = pd.from_edgelist(df, 'A', 'B')


      I saved it as a pickle



      nx.write_gpickle(g, 'myGraph.gz')


      I am now reading this graph for another project



      g = nx.read_pickle('myGraph.gz')


      I now have a datframe containing the information of some of the nodes in g.



      df1
      Node Y
      0 359 0
      1 576 1
      2 329 1
      3 278 0
      4 100 0
      5 437 1


      I want to use the information df.Y for the performing the personalized pagerank only for the nodes in common between df and g. After the merge I would like to have something like the following.



      d = pd.Series(df1['Y'], index=df1.index).to_dict()
      ppr = nx.pagerank(g, alpha=0.85, personalization=d)









      share|improve this question














      I have a networkx graph g that I created from a pandas dataframe df and I saved.



      df
      A B
      0 359 278
      1 576 437
      2 329 177
      3 329 278

      g = pd.from_edgelist(df, 'A', 'B')


      I saved it as a pickle



      nx.write_gpickle(g, 'myGraph.gz')


      I am now reading this graph for another project



      g = nx.read_pickle('myGraph.gz')


      I now have a datframe containing the information of some of the nodes in g.



      df1
      Node Y
      0 359 0
      1 576 1
      2 329 1
      3 278 0
      4 100 0
      5 437 1


      I want to use the information df.Y for the performing the personalized pagerank only for the nodes in common between df and g. After the merge I would like to have something like the following.



      d = pd.Series(df1['Y'], index=df1.index).to_dict()
      ppr = nx.pagerank(g, alpha=0.85, personalization=d)






      python pandas networkx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 11:44









      emaxemax

      1,21431235




      1,21431235
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337208%2fpython-how-to-merge-a-networkx-graph-with-a-dataframe%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337208%2fpython-how-to-merge-a-networkx-graph-with-a-dataframe%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues