[portland] Reformatting Data Files
Dylan Reinhardt
python at dylanreinhardt.com
Fri Jan 28 21:29:25 CET 2011
On Fri, Jan 28, 2011 at 11:44 AM, Rich Shepard <rshepard at appl-ecosys.com>wrote:
> The goal of the exercise is to write an output .csv file suitable for
> import to a database table. This means concatenating row 0, column 1 with
> row 1, column 1 and row 2, column 0, row 2, column 1, row 3, col 0, row 3,
> col 1, etc. In other words, I want the output to look like this:
>
>
To get a list of the concatenated values for column 0, 1, 2... how about:
---
column_values = list()
for col in range(3): # or whatever
column_values.append(' '.join([row[col] for row in reader]))
---
If you have a very large amount of data, it might be worth the extra time to
do it in one pass... but the above might be good enough for the task at
hand.
HTH,
Dylan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/portland/attachments/20110128/1c4a058b/attachment.html>
More information about the Portland
mailing list