Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #extract #values #column #json #format #python
ADD COMMENT
Topic
Name
7+9 =