[SciPy-user] Newbie: Reading a slice of a file

Vincent Nijs v-nijs at kellogg.northwestern.edu
Mon Jan 15 12:28:50 CST 2007


I don't think you can do that directly with pylab.load. You could do

data = pylab.load(f,delimiter=',',skiprows=n-10)

Where n = the length of the file.

You could probably do something more flexible with the csv module. The
following will read all your data into an array (assumes all elements are
floats). You can add-in selection conditions as needed.

import numpy
reader = csv.reader(file('yourfile.csv','r'))
data = numpy.array([i for i in reader])
data = data.astype('f')

Vincent


On 1/15/07 11:51 AM, "Chiara Caronna" <chiaracaronna at hotmail.com> wrote:

> I need to read just some rows of a file... do you know how to do it?
> I found out that with pylab.load I can skip some rows from the top, but I
> don't know how to skip from the bottom... maybe there is an other function?
> Thanks
> Chiara
> 
> 
>> From: Darren Dale <dd55 at cornell.edu>
>> Reply-To: SciPy Users List <scipy-user at scipy.org>
>> To: SciPy Users List <scipy-user at scipy.org>
>> Subject: Re: [SciPy-user] Can SciPy compute ln(640320**3 + 744)/163**.5
>> to30 places?
>> Date: Mon, 15 Jan 2007 12:19:58 -0500
>> 
>> On Monday 15 January 2007 11:52, Dick Moores wrote:
>>> That's great! Thanks!
>>> 
>>> Now, how about something such as (5/23)**(2/7)?
>>> print repr(n.exp(n.log(5/23)*2/7))
>>> gets ValueError: log domain error
>> 
>> integer division 5/23=0. The log of zero is either going to give you
>> -infinity
>> or an error.
>> 
>> Darren
>> _______________________________________________
>> SciPy-user mailing list
>> SciPy-user at scipy.org
>> http://projects.scipy.org/mailman/listinfo/scipy-user
> 
> _________________________________________________________________
> Don't just search. Find. Check out the new MSN Search!
> http://search.msn.com/
> 
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
> 

-- 
Vincent R. Nijs
Assistant Professor of Marketing
Kellogg School of Management, Northwestern University
2001 Sheridan Road, Evanston, IL 60208-2001
Phone: +1-847-491-4574 Fax: +1-847-491-2498
E-mail: v-nijs at kellogg.northwestern.edu
Skype: vincentnijs





More information about the SciPy-user mailing list