Created
June 22, 2017 21:09
-
-
Save mbstacy/8db451e885b34ec7178976cd10e93856 to your computer and use it in GitHub Desktop.
flatten_json.py
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
| import pandas as pd | |
| import json | |
| data =open("/Users/mstacy/Downloads/oessgpn.json","r").read() | |
| dflist=json.loads(data)['results'] | |
| df =pd.DataFrame(dflist) | |
| result = pd.concat([df, df['created_by'].apply(pd.Series)], axis=1).drop('created_by', axis=1) | |
| #endpoints | |
| endps=pd.DataFrame([x for x in result.endpoints]) | |
| endps.columns=['end1','end2'] | |
| endps.apply(pd.Series) | |
| result = pd.concat([result, endps['end1'].apply(pd.Series)], axis=1) #.drop('created_by', axis=1) | |
| result = pd.concat([result, endps['end2'].apply(pd.Series)], axis=1).drop('endpoints', axis=1) | |
| result.to_csv('result.csv') | |
| result[['description','circuit_id','name','node']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment