python extract certain fields from json array code example
Example 1: how to get specific data from json using python
with open('distros.json', 'r') as f:
distros_dict = json.load(f)
for distro in distros_dict:
print(distro['Name'])
Example 2: extract values from a column in json format python
import pandas as pd
d1 = '{"605":{"price":"570", "address":"946", "status": "done", "#result":"good" }}'
d2 = '{"254":{"price":"670", "address":"300", "status": "done", "classification_id": "102312321", "#result":"good" }}'
df = pd.DataFrame({'num': [1771, 905],
'item': ['orange', 'mango'],
'id': [190384, 2500003],
'data':[d1, d2],
'reg': [605, 254]
})
import json
df = df.join( pd.DataFrame(list(json.loads(d).values())[0] for d in df.pop('data')) )
del df['address']
del df['classification_id']
print(df)