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:
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: