[Numpy-discussion] how to build a series of arrays as I go?
Chris Withers
chris at simplistix.co.uk
Mon Mar 17 11:46:24 EDT 2008
Hi All,
I'm using xlrd to read an excel workbook containing several columns of
data as follows:
for r in range(1,sheet.nrows):
date = \
datetime(*xlrd.xldate_as_tuple(sheet.cell_value(r,0),book.datemode))
if date_cut_off and date < date_cut_off:
continue
for c in range(len(names)):
name = names[c]
cell = sheet.cell(r,c)
if cell.ctype==xlrd.XL_CELL_EMPTY:
value = -1
elif cell.ctype==xlrd.XL_CELL_DATE:
value = \
datetime(*xlrd.xldate_as_tuple(cell.value,book.datemode))
else:
value = cell.value
data[name].append(value)
Two questions:
How can I build arrays as I go instead of lists?
(ie: the last line of the above snippet)
Once I've built arrays, how can I mask the empty cells?
(the above shows my hack-so-far of turning empty cells into -1 so I can
use masked_where, but it would be greato build a masked array as I went,
for efficiencies sake)
cheers for any help!
Chris
PS: Slightly pissed off at actually paying for the book only to be told
it'll be 2 days before I can even read the online version, especially
given the woefully inadequate state of the currently available free
documentation :-(
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the NumPy-Discussion
mailing list