Python3.4:列表到CSV

时间:2015-06-10 13:32:41

标签: csv python-3.x

我试图将列表转换为csv。

import csv
import pandas as pd

cikList = []

with open('/home/a73nk-xce/PycharmProjects/SP500_list/stockChar/CIK.csv', 'r', newline='') as csvfile:
spamreader = csv.reader(csvfile)
for row in spamreader:
    for eachRow in row:
        eachRow = eachRow.lstrip('0')
        cikList.append(eachRow)

myfile = open('newCIK.csv', 'wb')
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
wr.writerow(cikList)

运行此代码时,我返回以下内容:

TypeError: 'str' does not support the buffer interface

1 个答案:

答案 0 :(得分:1)

变化:

myfile = open('newCIK.csv', 'wb')

要:

myfile = open('newCIK.csv', 'w')