[SciPy-user] Converting arrays to dates for plot_date()

John Hunter jdh2358@gmail....
Fri May 2 08:15:26 CDT 2008


On Fri, May 2, 2008 at 7:21 AM, Dharhas Pothina
<Dharhas.Pothina@twdb.state.tx.us> wrote:
> Thank you John, I tried that and got the error message :
>
>  TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'numpy.float64'
>
>  but using datetime() rather than datetime.date() seems to work.
>

I think the problem may be that you had floats rather than ints in
your "year" array.  For example, the following does work:


In [34]: data = array([1,2])

In [35]: year = array([2006,2007])

In [36]: month = array([11,12])

In [37]: day = array([1,2])

In [38]: dates = [datetime.date(y,m,d) for y,m,d in zip(year, month, day)]

In [39]: dates
Out[39]: [datetime.date(2006, 11, 1), datetime.date(2007, 12, 2)]

>  fyi. y'all have a great community here. I've asked two questions in the last few days and was
> answered quickly and correctly on both occasions.

Glad to help.

JDH


More information about the SciPy-user mailing list