Created
March 19, 2021 21:05
-
-
Save samirsaci/758bfd3df52fe181de17fc81672fab5b 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 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