【发布时间】:2023-04-02 16:43:01
【问题描述】:
my_dict = { 'company_a': [],
'company_b': [ {'gender': 'Male',
'investor': True,
'name': 'xyz',
'title': 'Board Member'} ],
'company_c': [],
'company_m': [ {'gender': 'Male',
'investor': None,
'name': 'abc',
'title': 'Advisor'},
{'gender': 'Male',
'investor': None,
'name': 'opq',
'title': 'Advisor'} ],
'company_x': [],
'company_y': [] }
如何将上述 Python 字典转换为具有这些列的 Pandas 数据框:company, gender, investor, name, title
company 列将由 my_dict 的顶级键填充。其他列将填充数组中字典中的值。
我尝试过pd.DataFrame.from_dict(my_dict, orient='index'),但它并没有给我想要的。
【问题讨论】:
标签: python dictionary pandas dataframe