0

This must be very simple.

I'm trying to put a header in my csv file, the string 'Date,Value', as you can see below.

with open('ticker.csv', 'wb') as f:

writer = csv.writer(f)
writer.writerows('Date,Value')
writer.writerows(izip(dates, values))
f.close()

However I'm getting a multirowed string, like this:

D

a

t

e

","

V

a

l

u

e

2002-03,12.9

2002-04,12.5

2002-05,11.9

How can I fix that?

1

2 Answers 2

1

Here is the solution

writer = csv.writer(f)
writer.writerow(['Date','Value'])
writer.writerows(izip(dates, values))
f.close()
Sign up to request clarification or add additional context in comments.

Comments

0

Use writerow - without the s - to write a single row.

1 Comment

thanks! almost there. now I'm getting D,a,t,e,",",V,a,l,u,e. How do I take out those commas between letters?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.