【发布时间】:2019-12-12 13:29:29
【问题描述】:
如何在python中将列表列表转换为CSV文件格式?
这就是我所拥有的,列表列表:
[
['Node', 'Resource', 'Actual Number', 'Maximum Number Allowed', 'Usage'],
['node1', 'AuC Data Management', '5586618', '5820000', '95%'],
['node2', 'Enhanced Multi-Level Precedence and Pre-Emption Service (eMLPP)', '1', '3001', '0%']
...
]
我想要什么 csv:
Node,Resource,Actual Number,Maximum Number Allowed,Usage
node1,AuC Data Management,5586618,5820000,95%
node2,Enhanced Multi-Level Precedence and Pre-Emption Service (eMLPP),1,3001,0%
...
抱歉,自从我研究 python 以来已经有一段时间了,这就是我目前正在做的事情:
>>> x
[['Node', 'Resource', 'Actual Number', 'Maximum Number Allowed', 'Usage'], ['node1', 'AuC Data Management', '5586618', '5820000', '95%'], ['node2', 'Enhanced Multi-Level Precedence and Pre-Emption Service (eMLPP)', '1', '3001', '0%']]
>>> x[0]
['Node', 'Resource', 'Actual Number', 'Maximum Number Allowed', 'Usage']
此外,是否有带有一些代码的库/资源可以针对列表列表可能出现的各种排列进行这种转换?
可能的相关问题:
Python csv file writing a list of lists
Writing a Python list of lists to a csv file
CSV IO python: converting a csv file into a list of lists
Write a list of lists into csv in Python
Convert this list of lists in CSV
【问题讨论】:
-
在这里请求库、工具或场外资源推荐是题外话。此外,StackOverflow 希望您能try to solve your own problem first,因为您的尝试有助于我们更好地了解您想要什么。请编辑问题以显示您尝试过的内容,并使用Minimal, Complete, and Verifiable example 显示您遇到的特定障碍。