Answers for "extract values from a column in json format python"

0

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')) )

# drop columns we don't want
del df['address']
del df['classification_id']

print(df)
Posted by: Guest on October-19-2020

Code answers related to "extract values from a column in json format python"

Code answers related to "Javascript"

Browse Popular Code Answers by Language