[Numpy-discussion] `missing` argument in genfromtxt only a string?

Pierre GM pgmdevlist@gmail....
Mon Sep 14 21:41:28 CDT 2009


On Sep 14, 2009, at 10:31 PM, Skipper Seabold wrote:
>
> I actually figured out a workaround with converters, since my missing
> values are " ","  ","   " ie., irregular number of spaces and the
> values aren't stripped of white spaces.  I just define {# : lambda s:
> float(s.strip() or 0)}, and I have a loop build all of the converters,
> but then I have to go through and drop the ones that are supposed to
> be strings or dates, which is still pretty tedious, since I have a
> number of datasets that are like this, but they all contain different
> data in different orders and there's no (computer) logical order to it
> that I've discovered yet.

I understand your frustration... We could think about some kind of  
global default for the missing values...
> I tried another workaround for the dates with my converters defined  
> as conv
>
> conv.update({date : lambda s : datetime(*map(int,
> s.strip().split('/')[-1:]+s.strip().split('/')[:2]))})
>
> Where `date` is the column that contains a date.  The problem was that
> my dates are "mm/dd/yyyy" and datetime needs "yyyy,mm,dd," it worked
> for a test case if my dates were "dd/mm/yyyy" and I just use reversed,
> but gave an error about not finding the day in the third position,
> though that lambda function worked for a test case outside of
> genfromtxt.

Check the archives of the mailing list, there's an example using  
dateutil.parser that may be just what you need.




More information about the NumPy-Discussion mailing list