【发布时间】:2021-09-05 01:25:03
【问题描述】:
我环顾四周,但似乎没有其他线程能完全回答我面临的具体挑战。
例如,this thread 告诉我如何将字典列表写入 CSV。
This one 解释了当每个键的值是一个列表时如何编写字典。
我有一个需要写入 CSV 的字典列表,其中只有一个值是一个列表。例如:
[{
'name': 'name_1',
'id': 'id_1',
'info': [{
'info_1': 'some info',
'info_2': 'more info'
},
{
'info_1': 'all the info',
'info_2': 'extra info'
}]
},
{
'name': 'name_2',
'id': 'id_2',
'info': [{
'info_1': 'another piece of info the same type as info_1 above',
'info_2': 'info'
},
{
'info_1': 'getting tedious',
'info_2': 'you get the picture...'
}
]
}]
输出标题是: 姓名、身份证、info_1、info_2
【问题讨论】:
-
您希望您的 csv 看起来像什么?您能否根据您的字典列表更新您的答案以包含示例输出。
-
道歉。更新了我的答案
标签: python list csv dictionary