I have the following code snippet, which loads data from a CSV file into a numpy.core.records.recarray:
r = mlab.csv2rec(datafile, delimiter=',', names=('dt', 'val'))
data = zip(date2num(r['dt']),r['val']) # Need to filter for records lying between two dates here ...
I want to only ‘zip’ records that have dates falling bewteen (say) ‘2000-01-01′ and 2000-03-01’
I understand the concept of lambda functions – but I haven’t used them before. It would be cool if I could use a lambda to filter the records between the required dates (like in pseudocode below):
data = zip(lambda: date2num(r['dt']),r['val'] if r['dt'] > '2000-01-01' and r['dt'] < '2000-03-01' )
What is the Pythonic way to extract a subset of data from the rec.array, based on specified indixes (i.e. dates)?
Lambda (often combined with map or filter) is generally a less pythonic and clear solution to the same problem that list comprehensions and its cousins solve.