I have the following data frame:
Src Dst
A [A,B]
B [B,A]
C [C]
D [D,E,F]
E [E,D,F]
F [F,D,E]
...
I would like to generate a ne
Here's a way to do that:
df["color"] = "blue"
df.loc[df.Src.isin(["A", "D"]), "color"] = "green"
# The following line is needed because, at least in the way my dataset
# is created, 'Dst' is not a list but rather a string.
# For example, Dst of 'A' is the string "[A,B]". Here,
# I'm converting it to the list ["A", "B"]
# If your data doesn't need this, just comment this line out.
df["Dst"] = df.Dst.apply(lambda x: x[1:-1].split(","))
G = nx.from_pandas_edgelist(df.explode("Dst"), 'Src', 'Dst')
nx.draw(G, node_color = df.color)
The output is: