csv中打印数据的python代码

时间:2016-11-22 06:34:29

标签: python-2.7 web-scraping

导入csv

reader = csv.reader(post.text,quotechar ="'")

打开(' source91.csv',' wb')为f:

  writer = csv.writer(f)
  writer.writerows(list(reader))

输出垂直显示我需要以CSV格式水平打印数据

1 个答案:

答案 0 :(得分:0)

简单回答:如果您只有一个数组

with open('source91.csv', 'wb') as f:
    writer = csv.writer(f, delimiter='\n')
    writer.writerows(list(reader))

复杂的答案:

您可能需要numpy来实现。 transpose只会将行转换为列

import numpy as np
a = np.array(list(reader))
a = np.append(a, list(reader)) # if you have multiple lines 
a = np.transpose(a)
np.savetxt('source91.csv', a)