小编Vic*_*tor的帖子

如何在 Python 上将列表的所有值导出到 csv

list_1 = ['1','2','3','4','5','6','7','8']
list_2 = ['n1','n2','n3','n4','n5','n6','n7','n8','n9','n10']
list_3 = ['o1','o2','o3','o4','o5','o6','o7','o8','o9','o10']

cols = zip(list_1,list_2,list_3)

with open('file.csv', 'w', newline='') as f:
    thewriter = csv.writer(f)

    thewriter.writerow(['list_1','list_2','list_3'])
    for col in cols:
       thewriter.writerow(col)
Run Code Online (Sandbox Code Playgroud)

输出

list1   list2   list3
  1      n1      o1
  2      n2      o2
  3      n3      o3
  4      n4      o4
  5      n5      o5
  6      n6      o6
  7      n7      o7
  8      n8      o8
Run Code Online (Sandbox Code Playgroud)

预期产出

list1   list2   list3
  1      n1      o1
  2      n2      o2
  3      n3      o3
  4      n4      o4
  5      n5      o5
  6      n6      o6
  7      n7      o7 …
Run Code Online (Sandbox Code Playgroud)

python csv list python-3.x

4
推荐指数
1
解决办法
62
查看次数

标签 统计

csv ×1

list ×1

python ×1

python-3.x ×1