You can provide a custom conversion function for a specific column to loadtxt
.
Since you are only interested in the year I use a lambda
-function to split the date on -
and to convert the first part to an int
:
data = np.loadtxt('delnorte.dat',
usecols=(2,3),
converters={2: lambda s: int(s.split('-')[0])},
skiprows=27)
array([[ 2000., 190.],
[ 2000., 170.],
[ 2000., 160.],
...,
[ 2010., 185.],
[ 2010., 175.],
[ 2010., 165.]])
To filter then for the year 2005
you can use logical indexing in numpy:
data_2005 = data[data[:,0] == 2005]
array([[ 2005., 210.],
[ 2005., 190.],
[ 2005., 190.],
[ 2005., 200.],
....])