Skip to content

Instantly share code, notes, and snippets.

@mbstacy
Created June 22, 2017 21:09
Show Gist options
  • Select an option

  • Save mbstacy/8db451e885b34ec7178976cd10e93856 to your computer and use it in GitHub Desktop.

Select an option

Save mbstacy/8db451e885b34ec7178976cd10e93856 to your computer and use it in GitHub Desktop.
flatten_json.py
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