0

I am trying to build a networkx digraph of blockchain transaction data and visualize it using Pyvis. I believe that I have the graph working, but I want to change the color of the transactions that involve Uniswap. I am having trouble doing that though as the colors never change. Here is my code:

G = nx.DiGraph()

# Read data in from csv and seperate data
data = pd.read_csv('apecoin_trans_data_1day_072822.csv')
fro = data['address_from']
to = data['address_to']
date_time = data['date_time']
amount = data['amount']

edges_data = zip(fro, to, date_time, amount)

transaction = []
# Create the graph
for e in edges_data:
    src = e[0]
    tar = e[1]

    G.add_node(src)
    G.add_node(tar)
    transaction.append((src, tar))

G.add_edges_from(transaction)
net = Network(height='750px', width='100%', notebook=False, directed=True)
net.from_nx(G)

# Get adjacency list for graph
neighbor_map = net.get_adj_list()


for node in net.nodes:
    node["value"] = len(neighbor_map[node["id"]])

    if node["id"] == "\xac4b3dacb91461209ae9d41ec517c2b9cb1b7daf":
        node["color"] = "red"
    else:
        node["color"] = "blue"


net.show("networkmap.html")

The data is formatted like so:

address_from,address_to,date_time,amount
\xdbb69ea87507525fffbd1c4f1ad6f7d30a9a402e,\x0000000000007f150bd6f54c40a34d7c3d5e9f56,2022-07-27T23:02:04+00:00,93.4673619317370716
\xba12222222228d8ba445958a75a0704d566bf2c8,\x0000000000007f150bd6f54c40a34d7c3d5e9f56,2022-07-27T23:02:30+00:00,95.7735945510702722
\xf784470541ad1f94902c387514756c7d831e20a7,\x0000000000007f150bd6f54c40a34d7c3d5e9f56,2022-07-28T00:06:38+00:00,8422.2499709617088153
\xf784470541ad1f94902c387514756c7d831e20a7,\x0000000000007f150bd6f54c40a34d7c3d5e9f56,2022-07-28T00:08:08+00:00,1337.1683051620927162
\x6eb0ed09ac237f4c607a18b8dc63b48efe61b9b8,\x00000000009726632680fb29d3f7a9734e3010e2,2022-07-28T13:57:26+00:00,1000.0000000000000000
Alex
  • 232
  • 1
  • 8

1 Answers1

1

I ended up figuring it out. I was doing the following:

 if node["id"] == "\xac4b3dacb91461209ae9d41ec517c2b9cb1b7daf"

When it should have been this:

if node["id"] == r'\xac4b3dacb91461209ae9d41ec517c2b9cb1b7daf'
Alex
  • 232
  • 1
  • 8