0

Im trying to generate a social network in networkx. To do this I want to use the barabasi_albert_graph network generator. I want to be able to generate the nodes separately in pandas so I can give them specific attributes, but then have the generator create the edges based on preferential attachment. Is this possible?

The documentation for the generator just explains how to generate based on numbers of nodes and edges like so

G = nx.barabasi_albert_graph(600, 2, seed=None)

The documentation for from_pandas_dataframe just shows how to create a graph from a dataframe with edges already like so

G =nx.from_pandas_dataframe(df2, 'nodes', 'edges', ['attributes'])

In more an exploratory way rather than "this code doesnt work", I need something like

G = nx.barabasi_albert_graph.from_pandas_dataframe()

The purpose of this is to generate a model of an organisational communication network. I need the nodes to have attributes of a hierarchy (department, job title, salary) but the edges to be created using preferential attachment.

  • If you could give some examples to describe the problems will be good. I am not sure what kind of help you want? code? or some relative documents? If you want some helpful code without example data, we can't help. – tianhua liao Oct 03 '18 at 14:10
  • Hopefully that makes more sense now – Liam Mcconnachie Oct 03 '18 at 14:16

1 Answers1

0

Ok, I think I know what you want. First, I think there are not any functions like nx.barabasi_albert_graph.from_pandas_dataframe(), because it just is a simple generator for some special need.

If you really want to do that, I recommend that you could use API of networx to add attributes into a generated graph. (It also some notes you should know. nx.from_pandas_dataframe has been obsoleted at latest networkx version.)

Just like

G.nodes[1]['room'] = 714

From the source code of barabasi_albert_graph, It also just randomly generating a list of nodes and append some edges followed the preferential attachment.

If you still have some problems about how to add attributed from dataframe into existing graph, you could comment under this answer.

tianhua liao
  • 655
  • 5
  • 9