给定从df['statistics'].head().to_dict()
创建的以下词典
{0: {'executions': {'total': '1',
'passed': '1',
'failed': '0',
'skipped': '0'},
'defects': {'product_bug': {'total': 0, 'PB001': 0},
'automation_bug': {'AB001': 0, 'total': 0},
'system_issue': {'total': 0, 'SI001': 0},
'to_investigate': {'total': 0, 'TI001': 0},
'no_defect': {'ND001': 0, 'total': 0}}},
1: {'executions': {'total': '1',
'passed': '1',
'failed': '0',
'skipped': '0'},
'defects': {'product_bug': {'total': 0, 'PB001': 0},
'automation_bug': {'AB001': 0, 'total': 0},
'system_issue': {'total': 0, 'SI001': 0},
'to_investigate': {'total': 0, 'TI001': 0},
'no_defect': {'ND001': 0, 'total': 0}}},
2: {'executions': {'total': '1',
'passed': '1',
'failed': '0',
'skipped': '0'},
'defects': {'product_bug': {'total': 0, 'PB001': 0},
'automation_bug': {'AB001': 0, 'total': 0},
'system_issue': {'total': 0, 'SI001': 0},
'to_investigate': {'total': 0, 'TI001': 0},
'no_defect': {'ND001': 0, 'total': 0}}},
3: {'executions': {'total': '1',
'passed': '1',
'failed': '0',
'skipped': '0'},
'defects': {'product_bug': {'total': 0, 'PB001': 0},
'automation_bug': {'AB001': 0, 'total': 0},
'system_issue': {'total': 0, 'SI001': 0},
'to_investigate': {'total': 0, 'TI001': 0},
'no_defect': {'ND001': 0, 'total': 0}}},
4: {'executions': {'total': '1',
'passed': '1',
'failed': '0',
'skipped': '0'},
'defects': {'product_bug': {'total': 0, 'PB001': 0},
'automation_bug': {'AB001': 0, 'total': 0},
'system_issue': {'total': 0, 'SI001': 0},
'to_investigate': {'total': 0, 'TI001': 0},
'no_defect': {'ND001': 0, 'total': 0}}}}
是否有办法将字典键/值对扩展到它们自己的列中,并在这些列前面加上原始列的名称,即statistics.executions.total将变成statistics\u executions\u total甚至executions\u total
我已经演示了我可以使用以下方法创建列:
pd.concat([df.drop(['statistics'], axis=1), df['statistics'].apply(pd.Series)], axis=1)
但是,您会注意到,每个新创建的列都有一个重复的名称“total”
一,;但是,我们无法找到一种方法,在新创建的列前面加上原始列名,即:executions_total
为了进一步了解,统计将扩展到执行和缺陷,执行将扩展到通过|失败|跳过|总数,缺陷将扩展到自动化|系统|问题|调查|产品|缺陷|无|缺陷。随后,后者将扩展为total |**001列,其中total重复了几次
非常感谢您的任何想法-谢谢
.apply(pd.Series)
速度很慢,不要使用它。dict
创建一个带有'statistics'
列的数据帧。'statistics'
列上使用^{sep
是.
。sep
分隔的名称李>相关问题 更多 >
编程相关推荐