我有这个数据框架有4列。我想在一个单独的列中提取resourceName(即id)。我尝试了各种方法和循环,但无法将其分离。
数据集:
用户名 | 事件名称 | 资源 | XYZ-DEV_ENV_POST_function | StopInstances | [{"resourceType"AWS: EC2:: Instance","resourceName":"i-05fbb7a"}] |
---|---|---|
XYZ-DEV_ENV_POST_function | StartInstances | [{"resourceType"AWS: EC2:: Instance","resourceName":"i-08bd2475"},{"resourceType"AWS: EC2:: Instance","resourceName":"i-0fd69dc1"},{"resourceType"AWS: EC2:: Instance","resourceName":"我- 0174 dd38aea"}] |
df['ID'] = df['Resources'].apply(lambda x: ','.join([i['resourceName'] for i in eval(x)]))
Date ... ID
0 28-02-2022 ... i-05fbb7a
1 28-02-2022 ... i-08bd2475,i-0fd69dc1,i-0174dd38aea