Created
June 18, 2021 04:23
-
-
Save McKlayne/2fcbeccda2a358fa002f66b5648b9c09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def define_edges(crypto_ids, crypto_abbreviations, crypto_data): | |
# initialize the graph and an empty list for edges | |
graph = nx.DiGraph() | |
edges = [] | |
# define all edges and add to graph | |
for coin1 in crypto_ids: | |
for coin2 in crypto_ids: | |
if coin1 != coin2: | |
# find the index of coin1 and coin2 in the ids list. Use those values to get the abbreviations | |
coin1_index = crypto_ids.index(coin1) | |
coin2_index = crypto_ids.index(coin2) | |
edges.append((crypto_abbreviations[coin1_index], crypto_abbreviations[coin2_index], crypto_data[coin1][crypto_abbreviations[coin2_index]])) | |
# print(edges) | |
graph.add_weighted_edges_from(edges) | |
return(graph) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment