extract values from a column in json format python

Solutions on MaxInterview for extract values from a column in json format python by the best coders in the world

showing results for - "extract values from a column in json format python"
Clara
02 Nov 2017
1import pandas as pd
2
3d1 = '{"605":{"price":"570", "address":"946", "status": "done", "#result":"good" }}'
4d2 = '{"254":{"price":"670", "address":"300", "status": "done", "classification_id": "102312321", "#result":"good" }}'
5
6df = pd.DataFrame({'num': [1771, 905],
7                  'item': ['orange', 'mango'],
8                  'id': [190384, 2500003],
9                  'data':[d1, d2],
10                  'reg': [605, 254]
11    })
12
13
14import json
15df = df.join( pd.DataFrame(list(json.loads(d).values())[0] for d in df.pop('data')) )
16
17# drop columns we don't want
18del df['address']
19del df['classification_id']
20
21print(df)
22