Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created March 19, 2021 21:05
Show Gist options
  • Select an option

  • Save samirsaci/758bfd3df52fe181de17fc81672fab5b to your computer and use it in GitHub Desktop.

Select an option

Save samirsaci/758bfd3df52fe181de17fc81672fab5b to your computer and use it in GitHub Desktop.
def create_json(df_nodes, df_links):
''' Create json from dataframes'''
json1 = []
for index, row in df_nodes.reset_index().iterrows():
dico = {}
dico['group'] = int(row['group'])
dico['name'] = row['name']
json1.append(dico)
json2 = []
for index, row in df_links.iterrows():
dico = {}
dico['source'] = int(row['source'])
dico['target'] = int(row['target'])
dico['value'] = int(row['value'])
json2.append(dico)
json_to = {"links": json2, "nodes": json1}
return json_to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment