Python numpy loadtxt fails with date time
Question: I am trying to use numpy loadtxt to load a csv file into an array. But it seem
i can't get the date time correctly loaded.

Below demonstrates what is happening. Did I do something wrong?

    
    
    >>> s = StringIO("05/21/2007,03:27")
    >>> np.loadtxt(s, delimiter=",", dtype={'names':('date','time'), 'formats':('datetime64[D]', 'datetime64[m]')})
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/npyio.py", line 796, in loadtxt
    items = [conv(val) for (conv, val) in zip(converters, vals)]
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/npyio.py", line 573, in <lambda>
      return lambda x: int(float(x))
    ValueError: invalid literal for float(): 05/21/2007
    


Answer: Trying MichealJCox's solution did not work for me. My version of numpy (1.8)
would not accept a time number as given by `strpdate2num('%m/%d/%Y')`, it
would only accept a date string or datetime object. Therefore, I used a more
complex converter, which converts the time string to a time number and then to
a datetime object usable by numpy :

    
    
    from matplotlib.dates import strpdate2num, num2date
    ...
    convert = lambda x: num2date(strpdate2num('%m/%d/%Y')(x))
    np.loadtxt(s, delimiter=",", converters={0:convert}, dtype= ...
    

This seems like a bulky solution though.

