[Tutor] Extracting columns from CSV
vishwajeet singh
dextrous85 at gmail.com
Sun Oct 11 14:46:25 CEST 2009
On Sun, Oct 11, 2009 at 6:10 PM, Utkarsh "" <livinglif3 at gmail.com> wrote:
> Hello, I have a CSV file, from which I want to extract data.
> The CSV file is arranged like this:
>
> Time, InSec, Open, High, Low, Close, Qty
> 09:55:17,35717,41.95,41.95,41.95,41.95,105
> 09:56:03,35763,41.75,41.75,41.75,41.75,20785
> 09:56:40,35800,41.75,41.75,41.75,41.75,8950
>
> I wanted to extract each column, and put the data in a list, with a list
> for each column.
> I'm using the following code to perform this action:
>
> Time, InSec, Open, High, Low, Close, Volume = [], [], [], [], [], [],
> []
> thefile = open('somefile.CSV', 'r')
> linelist = thefile.readline()
> while linelist != '':
> b = linelist.split(',')
> Time.append(b[0])
> InSec.append(b[1])
> Open.append(b[2])
> High.append(b[3])
> Low.append(b[4])
> Close.append(b[5])
> Volume.append(b[6])
> linelist = thefile.readline()
>
> Is there any other, better and more pythonic way to do this ?
>
> you can take a look at csv module
http://docs.python.org/library/csv.html
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Vishwajeet Singh
+91-9657702154 | dextrous85 at gmail.com | http://singhvishwajeet.com
Twitter: http://twitter.com/vishwajeets | LinkedIn:
http://www.linkedin.com/in/singhvishwajeet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091011/aa411263/attachment.htm>
More information about the Tutor
mailing list