Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79249

Re: Write list to new column in existent csv

From Peter Otten <__peter__@web.de>
Subject Re: Write list to new column in existent csv
Date 2014-10-17 20:08 +0200
Organization None
References <a888d7a9-efe5-4887-a495-201c9002232e@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.14948.1413569341.18130.python-list@python.org> (permalink)

Show all headers | View raw


Tal Bar-Or wrote:

> I am tryin to figure how to write a list i have as follows

> To a a csv to for example the 3rd column , i am really got stacked here i
> tried few codes with csv.writerow() but didn't got it work ,will really
> appreciate if someone could help me with that Please advice Thanks

Here's a sketch:

Open the source file using a csv.reader(); open the destination file using a 
csv.writer().

Use zip() and a for-loop to iterate over the new column and the rows in the 
source.

Insert the new field into the source row, e. g. row.insert(3, field)

Use writerow() to write the modified row.

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Write list to new column in existent csv Tal Bar-Or <tbaror@gmail.com> - 2014-10-17 09:56 -0700
  Re: Write list to new column in existent csv Peter Otten <__peter__@web.de> - 2014-10-17 20:08 +0200

csiph-web