使用pandas从数据框中的字典列表中提取值
我有这个带有4列的数据框。我想在一个单独的列中提取ResourceName(IE ID)。我尝试了各种方法和循环,但无法将其分开。
数据集:
用户名 | 事件名称 | 资源 |
---|---|---|
xyz-dev_env_post_function | [ | “ I-05FBB7A”} |
stopInstances | {“ resourceType”: “ | aws :: ec2 :: ec2 ::实例”,“ resourcename” : :ec2 ::实例“,“ resourceName”:“ I-08BD2475”},{“ resourceType”:“ aws :: ec2 :: ec2 ::实例”,“ resourcename”:“ i-0fd69dc1”} AWS :: ec2 ::实例“,“ resourceName”:“ I-0174DD38AEA”}] |
我想要一个将具有来自Resource列的ID的列ID,LL看起来像这样:
用户名 | 事件名称 | xyz | - |
---|---|---|---|
dev_env_env_env_env_env_post_function_function | stopinstances | [{{{{ {{{{{{{{{{{{{{{ “ ResourceType”:“ AWS :: ec2 ::实例”,“ ResourceName”:“ I-05FBB7A”}] | I-05FBB7A“ |
XYZ-DEV_ENV_ENV_ENV_POST_FUNCTICT_FUNCTICTANCES | [ | {“ resourceType)[{“ resourcetype” ResourceName“:” I-08BD2475“},{“ resourceType”:“ aws :: ec2 :: Instance”,“ resourcename”:“ i-0fd69dc1”},{“ resourceType” ,“ ResourceName”:“ I-0174DD38AEA”}] | I-08BD2475,I-0FD69DC1,I-0174 |
这是Data.head(2).TO_DICT():
{'date':':':':':': {0:'28 -02-2022',1:'28 -02-2022'}, “事件名称”: {0:'stopinstances',1:'startInstances'}, '资源': { 0:'[{“ resourceType”:“ aws :: ec2 :: instance”,“ resourcename”:“ i-05fbb7a”}], 1:'[{“ resourceType”:“ aws :: ec2 :: instance”,“ resourceName”:“ i-08BD2475”},{“ resourceType”:“ aws :: ec2 :: ec2 ::实例”,“ resourceName”,“ resourceName”:“:” i-0fd69dc1“},{“ resourceType”:“ aws :: ec2 ::实例”,“ resourcename”:“ I-0174DD38AEA”}]'}, '用户名':{0:'xyz-dev_env_post_function',1: 'xyz-dev_env_post_function'}}
谢谢,
I have this dataframe with 4 columns. I want to extract resourceName (i.e IDs ) in one separate column. I tried various methods and loops but unable to seperate it.
Dataset:
Username | Event name | Resources |
---|---|---|
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":"i-0174dd38aea"}] |
I want one more column IDs which will have IDS from Resource column and ll look like this:
Username | Event name | Resources | IDS |
---|---|---|---|
XYZ-DEV_ENV_POST_function | StopInstances | [{"resourceType":"AWS::EC2::Instance","resourceName":"i-05fbb7a"}] | 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":"i-0174dd38aea"}] | i-08bd2475 , i-0fd69dc1 , i-0174 |
Here is output of data.head(2).to_dict():
{'Date':
{0: '28-02-2022', 1: '28-02-2022'},
'Event name':
{0: 'StopInstances', 1: 'StartInstances'},
'Resources':
{
0: '[{"resourceType":"AWS::EC2::Instance","resourceName":"i-05fbb7a"}]',
1: '[{"resourceType":"AWS::EC2::Instance","resourceName":"i-08bd2475"},{"resourceType":"AWS::EC2::Instance","resourceName":"i-0fd69dc1"},{"resourceType":"AWS::EC2::Instance","resourceName":"i-0174dd38aea"}]'},
'User name': {0: 'XYZ-DEV_ENV_POST_function', 1:
'XYZ-DEV_ENV_POST_function'}}
Thanks and Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)