我有一個字典的結構,我需要遍歷它以查找鍵“items”下是否在鍵欄位下有值“status”和鍵“toString”下的值“In Progress” .
另外,我需要知道它發生的日期。在“created”鍵下查找值時,可以找到更高一級的值。
我嘗試了很多方法,但沒有任何效果。我感謝您的幫助。
{'startAt': 0,
'maxResults': 18,
'total': 18,
'histories': [{'id': '126221979',
'author': {'self': '<some_URL>',
'name': '<ID in the system>',
'key': '<ID in the system>',
'emailAddress': 'e-mail address',
'avatarUrls': {'48x48': '<some_URL>',
'24x24': '<some_URL>',
'16x16': '<some_URL>',
'32x32': '<some_URL>'},
'displayName': 'Display Name',
'active': True,
'timeZone': 'America/Sao_Paulo'},
'created': '2022-02-11T19:22:40.000 0000',
'items': [{'field': 'Link',
'fieldtype': 'jira',
'from': None,
'fromString': None,
'to': '<Isue ID>',
'toString': 'This issue child-of <Some ID>'}]},
{'id': '126221981',
'author': {'self': '<some_URL>',
'name': '<ID in the system>',
'key': '<ID in the system>',
'emailAddress': 'e-mail address',
'avatarUrls': {'48x48': '<some_URL>',
'24x24': '<some_URL>',
'16x16': '<some_URL>',
'32x32': '<some_URL>'},
'displayName': 'Display Name',
'active': True,
'timeZone': 'America/Sao_Paulo'},
'created': '2022-02-11T19:23:56.000 0000',
'items': [{'field': 'status',
'fieldtype': 'jira',
'from': 1,
'fromString': 'Open',
'to': 3,
'toString': 'In Progress'}
]
},
{'id': '126221981',
'author': {'self': '<some_URL>',
'name': '<ID in the system>',
'key': '<ID in the system>',
'emailAddress': 'e-mail address',
'avatarUrls': {'48x48': '<some_URL>',
'24x24': '<some_URL>',
'16x16': '<some_URL>',
'32x32': '<some_URL>'},
'displayName': 'Display Name',
'active': True,
'timeZone': 'America/Sao_Paulo'},
'created': '2022-02-11T19:23:56.000 0000',
'items': [{'field': 'status',
'fieldtype': 'jira',
'from': 1,
'fromString': 'Open',
'to': 3,
'toString': 'In Progress'}
]
}
]
}
uj5u.com熱心網友回復:
使用pd_json_normalize:
>>> pd.json_normalize(d['histories'], 'items', 'created')
field fieldtype from fromString to toString created
0 Link jira NaN None <Isue ID> This issue child-of <Some ID> 2022-02-11T19:22:40.000 0000
1 status jira 1.0 Open 3 In Progress 2022-02-11T19:23:56.000 0000
2 status jira 1.0 Open 3 In Progress 2022-02-11T19:23:56.000 0000
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/432093.html
上一篇:從匹配鍵上的字典值創建新的df列
