-1

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?

2
  • Does the column contain strings (text in the JSON format), or does it contain already-parsed JSON data? Oct 7, 2022 at 5:59
  • It contains parsed json data Oct 7, 2022 at 6:33

1 Answer 1

0

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:

1
  • 1
    Thank you for the timely response, it resolved the issue. Oct 7, 2022 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.