我已经纠结了一两天了,我似乎不能把它做对。
project_index = [
{A: ['1', '2', '3']},
{B: ['4', '5', '6']},
{C: ['7', '8', '9']},
{D: ['10', '11', '12']},
{E: ['13', '14', '15']},
{F: ['16', '17', '18']}
]
我已经尝试了很多不同的方法来尝试将其放入.CSV表中,但它总是以可笑的错误格式出现,例如它们沿对角线平铺,或者一系列的键反复出现(例如:
A、B、C、D、E、F
A、B、C、D、E、F
A、B、C、D、E、F
A、B、C、D、E、F)
而且,即使我得到了要显示的值,整个字符串数组也会显示在一个单元格中。
有没有办法让它把每个字典都变成一个列,数组中的每个字符串值都作为该列中自己的单元格?
示例:x1c 0d1x
提前感谢您!
2条答案
按热度按时间20jt8wwn1#
假设你所有的键都是唯一的......那么这个(稍微修改):
应该看起来像这样:
在这一点上,与其重新发明轮子......不如使用
pandas
。输出
file.csv
:csv
模块方法:bogh5gae2#
我的解决方案不使用Pandas。计划如下:
zip
转置列-〉行输出.csv的内容: