I am trying to create a directed graph upon this dataset:
ID Link_to Label Date Size
0 mary NaN 0 2020-01-23 1
1 Julie Mirk 1 2020-02-27 12
1 Julie Mark 1 2020-02-27 12
1 Julie Sarah 1 2020-02-27 12
1 Chris Mirk 1 2020-01-26 12
... ... ... ... ... ... ...
50 Mirk Chris 0 2020-04-29 4
51 Mark NaN 0 2020-04-29 3
52 Greg NaN 0 2020-04-27 2
53 Luke Matt 0 2020-04-08 1
54 Sarah James 0 2020-04-01 1
To create an undirected graph with my data above, I did:
G = nx.from_pandas_edgelist(df, 'ID', 'Link_to')
d = dict(df.drop_duplicates(subset=['ID'])[['ID']]
.to_numpy().tolist())
nodes = G.nodes()
plt.figure(figsize=(20,33))
pos = nx.draw(G, with_labels=True,
nodelist=nodes,
node_color=[d.get(i,'lightgreen') for i in nodes],
node_size=1000)
I would like to add date information in the graph, in order to create a directed graph: the ID who has the earliest date is the source. So for example: Julie and Mirk are linked together: a directed link from Julie to Mirk should be added.
Another example: Chris and Mirk are connected to each other. However, since Chris has an earliest date compared to ID's than connect Mirk to Chris. If two IDs are linked to each other and they have the same date, they should have one arrows (bidirectional).
How can I figure out how to add Date information in my graph?
