Home > OS >  How to extract a json object in an excel column using python?
How to extract a json object in an excel column using python?

Time:10-07

I have an excel file with one of the columns as json array. I want to extract the value of "name" from the object against the particular "sid".Below is the input:

SID Sumary
101 [{'xid': 'Dseabc101', 'name': 'event1'}, {'xid': '5Radesc', 'name': 'Event2'}]
102 [{'xid': '3a65a2', 'name': 'Event3'}]

The expected output should be: enter image description here

Can someone please help me with this?

CodePudding user response:

Use:

df['Summary'] = df['Summary'].apply(lambda x: ','.join(y['name'] for y in x))

df['Summary'] = [','.join(y['name'] for y in x) for x in df['Summary']]

If possible strings in column Summary use:

import ast

df['Summary']=df['Summary'].apply(lambda x:','.join(y['name'] for y in ast.literal_eval(x)))

Or:

  • Related