From: Francesc A. <fa...@ca...> - 2006-09-15 14:06:05
|
A Divendres 15 Setembre 2006 15:57, Robert Kern va escriure: > Lionel Roubeyrie wrote: > > Hi all, > > I try to use recarray with rec.fromrecords on time-series, datas come > > from a file where they are stored in csv format, with after each data > > colum there is one column meanning the state of the data, and the first > > column is for dates. Then, is it possible to directly transform column = of > > strings to a integer one (or datetime one), and to remove a not used > > column? > > When I import CSV files into record arrays, I usually read in all of the > data and transpose the list of rows to get a list of columns. Then I can > remove columns and transform them _en masse_, usually with map(). Another possibility is to play with columns directly from the initial=20 recarray. The next is an example: In [101]: ra=3Dnumpy.rec.array("1"*36, dtype=3D"a4,i4,f4", shape=3D3) In [102]: ra Out[102]: recarray([('1111', 825307441, 2.5784852031307537e-09), ('1111', 825307441, 2.5784852031307537e-09), ('1111', 825307441, 2.5784852031307537e-09)], dtype=3D[('f0', '|S4'), ('f1', '<i4'), ('f2', '<f4')]) In [103]: rb=3Dnumpy.rec.fromarrays([numpy.array(ra['f0'], 'i4'),ra['f2']],= =20 names=3D'f0,f1') In [104]: rb Out[104]: recarray([(1111, 2.5784852031307537e-09), (1111, 2.5784852031307537e-09), (1111, 2.5784852031307537e-09)], dtype=3D[('f0', '<i4'), ('f1', '<f4')]) where ra is the original recarray and rb is a derived one where its first=20 column is the original from ra, but converted to integers ('i4'), and the=20 second it's the third column from ra (so the second column from ra has been= =20 stripped out from rb). HTH, =2D-=20 >0,0< Francesc Altet =A0 =A0 http://www.carabos.com/ V V C=E1rabos Coop. V. =A0=A0Enjoy Data "-" |