[Tutor] Fw: Fw: Fw: Parsing data from a csv file [NC]
Louis LEICHTNAM
louis.leichtnam at sgcib.com
Thu Mar 24 16:48:52 CET 2011
For example the line 1 in the csv file is:
Barney Gumble, Breakfast, Duffbeer, 1, I could?ve gone to Harvard
and I want to be able to clean it and turn it into:
Barney Gumble had for beakfast 1 Duffbeer while thinking "I coul?ve gone
to Harvard"
so basically using in this line the column0 + "had for " + column 1 +
column3 + column2 + "while thinking"+column4
and I want to be able to do this for every line, except for line0.
My end game is, after I'm able to do this, I want to write an Html using
python that shows those cleand lines
Thanks for your help
l.leichtnam at gmail.com
03/24/2011 11:39 AM
Please respond to
l.leichtnam at gmail.com
To
Louis LEICHTNAM/us/socgen at socgen
cc
Subject
Fw: [Tutor] Fw: Fw: Parsing data from a csv file [NC]
Ok, I think what you are trying is to get all data in a string list:
import urllib, csv
url=r"http://www.cs.columbia.edu/~joshua/teaching/cs3101/simpsons_diet.csv
"
simpsons=urllib.urlopen(url)
reader=csv.reader(simpsons,delimiter=',',quotechar='"')
list_string = []
for char,meal,ate,qty,com in reader:
if char != 'Character':
list_string.append("%s %s %s %s %s" % (char, meal, ate, qty, com))
print list_string
Doing something like this you can format all strings as you want and keep
them into a list
2011/3/24 <l.leichtnam at gmail.com>
Thanks, what I'm trying to do is extract the data from the csv file, clean
it to make each line into a sentence.
But for this I think I need to use a dictionary for each and enter the
words of each columns in one no?
Sent from my BlackBerry® on the MetroPCS Network
-----Original Message-----
From: Rafael Durán Castañeda
<rafadurancastaneda at gmail.com>
Sender: tutor-bounces+l.leichtnam=gmail.com at python.org
Date: Thu, 24 Mar 2011 15:51:34
To: <tutor at python.org>
Subject: Re: [Tutor] Fw: Fw: Parsing data from a csv file [NC]
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
*************************************************************************
This message and any attachments (the "message") are confidential, intended
solely for the addressee(s), and may contain legally privileged information.
Any unauthorised use or dissemination is prohibited. E-mails are susceptible
to alteration. Neither SOCIETE GENERALE nor any of its subsidiaries or
affiliates shall be liable for the message if altered, changed or falsified.
*************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110324/9ee938c4/attachment.html>
More information about the Tutor
mailing list