Last active
July 21, 2018 12:25
-
-
Save traderbagel/c3b2f691b98a9009fcb69edd92f4422e to your computer and use it in GitHub Desktop.
build graph from transactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from decimal import Decimal | |
import networkx as nx | |
edges = defaultdict(lambda :defaultdict(Decimal)) | |
for tx in eth_transactions: | |
edges[tx.from_address][tx.to_address] += tx.amount | |
G = nx.DiGraph() | |
G.add_weighted_edges_from([(f, t, edges[f][t]) for f | |
in edges for t in edges[f] if edges[f][t] > Decimal(100)]) | |
print(nx.info(G)) | |
''' Output | |
Name: | |
Type: DiGraph | |
Number of nodes: 349 | |
Number of edges: 296 | |
Average in degree: 0.8481 | |
Average out degree: 0.8481 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment