[SciPy-user] Sort by first n columns in an array
Dharhas Pothina
Dharhas.Pothina at twdb.state.tx.us
Fri Jul 10 08:26:11 EDT 2009
Yes, but I don't need just the first six columns sorted, I need the *entire* dataset (ie all columns) sorted by date.
- dharhas
>>> Neil Crighton <neilcrighton at gmail.com> 7/10/2009 6:26 AM >>>
Dharhas Pothina <Dharhas.Pothina <at> twdb.state.tx.us> writes:
> >>> Neil Crighton <neilcrighton <at> gmail.com> 7/8/2009 6:14 PM >>>
> >Something like this should work:
> >
> >data = np.genfromtxt(filename, dtype=None, usecols=(0,1,2),
> > names='year,month,day')
> >data.sort(order=['year', 'month', 'day'])
>
> That works if I know the number of columns prior to reading the file. In this
case I'm reading a file with an
> unknown number of columns. I know that the first six columns are the date
fields.
>
If you know the first six columns are the date fields, can't you use
data = np.genfromtxt(filename, dtype=None, usecols=(0,1,2,3,4,5),
names='year,month,day,hour,min,sec')
?
That doesn't make any assumption about the number of columns (as long as
there's at least six of them).
Neil
_______________________________________________
SciPy-user mailing list
SciPy-user at scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list