Aran Freel
Aran Freel

Reputation: 3215

Python3.4 : List to CSV

I'm trying to convert a list to a 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)

When running this code I return the following:

TypeError: 'str' does not support the buffer interface

Upvotes: 0

Views: 57

Answers (1)

Aran Freel
Aran Freel

Reputation: 3215

Change:

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

To:

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

Upvotes: 1

Related Questions