Created
April 9, 2015 15:00
-
-
Save teh/89f93bcc911a3c664789 to your computer and use it in GitHub Desktop.
This file contains 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 get_records(): | |
df = pandas.read_json('1.json') | |
df = pandas.io.json.json_normalize(df['accidents']) | |
for _, row in df.iterrows(): | |
for c in row['casualties']: | |
for i in row['involved']: | |
row['caualty_severity'] = c['severity'] | |
row['caualty_gender'] = c['gender'] | |
row['caualty_class'] = c['class'] | |
row['caualty_vehicle'] = c.get('vehicle', 'unknonwn') | |
row['involved_id'] = i['id'] | |
row['involved_type'] = i['type'] | |
yield row | |
df = pandas.DataFrame.from_records(get_records()) | |
del df['casualties'] | |
del df['involved'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment