我有一个摘录,其中包含以下格式的几个JSON字符串:
{'assignedTo': 'a5060ed2', 'automated': 'Not Automated', 'build': None, 'configurationId': 123,
'configurationName': 'Package 1.0', 'lastResultState': 1, 'lastRunBy': '', 'lastRunDuration': 0,
'mostRecentResultOutcome': 2, 'mostRecentRunId': 1234, 'outcome': 'Passed', 'state': 2,
'suiteId': 1234, 'suiteName': 'Name', 'testCaseId': 12345, 'testPointId': 12345, 'tester': 'Fred Smith',
'workItemProperties': [{'Key': 'System.Id', 'Value': 12345}, {'Key': 'System.Title', 'Value': 'Item Item'},
{'Key': 'System.IterationPath', 'Value': 'Path\Path'},
{'Key': 'System.ChangedDate', 'Value': '/Date(1554200489873)/'},
{'Key': 'System.ChangedBy', 'Value': 'Fred Smith'},
{'Key': 'Microsoft.VSTS.TCM.AutomationStatus', 'Value': 'Not Automated'}]}
我已经能够循环这些内容,并在一个数据帧中显示它们,将每个字符串作为新行追加,但我遇到了一个问题。我的json字符串中有一个字段列表:
assignedTo
etc
workItemProperties < - this is the last field in the list
最后一个字段“WorkTempProperties”的值为:
[{'Key': 'System.Id', 'Value': 12345}, {'Key': 'System.Title', 'Value': 'Item Item'},
{'Key': 'System.IterationPath', 'Value': 'Path\Path'},
{'Key': 'System.ChangedDate', 'Value': '/Date(1554200489873)/'},
{'Key': 'System.ChangedBy', 'Value': 'Fred Smith'},
{'Key': 'Microsoft.VSTS.TCM.AutomationStatus', 'Value': 'Not Automated'}]
我希望能够在表中显示该值中包含的字段,因此我的字段列表如下所示:
assignedTo
…
workItemProperties
System.Id
System.Title
System.IterationPath
Etc
有没有可能让panda从worktemproperty的值中提取并识别这些“子”字段和值?或者我需要做一些进一步的字符串提取/操作吗
您可以使用
json_normalize
例如:
输出:
公认的答案非常有效,但有人向我建议的另一种选择也很有效:
这会将子字段和值与其余数据一起完全展平到列中
相关问题 更多 >
编程相关推荐