On Mon, May 21, 2012 at 11:47 AM, Jeremy Traurig <jeremy.trau...@gmail.com> wrote: > Hello, > > Is there a module available for python to convert datetime into an > array of integers. For example, I have date where the first column is > a datetime string (i.e. '2010-10-10 01:10:00') and I would like to > convert that into an array with 5 columns corresponding to the integer > values of Year,Month,Day,Hour,Minute. There is a function in Matlab > that performs called datevec() that performs this operation. I find it > much easier to index datetime or perform calculations on other data > when date and time are integers. For example, i generally need to > calculate averages, std, etc based on specific months, years, days, > and hours. Those calculations are extremely simple when I can index an > array of datetime integers. If there is no module to convert datetime > to an array of integers, does anyone have an example of how i might > index datetime using python datetime or numpy datetime64? In each > case, I would need an array of datetime the same dimension as my data > array. > > thanks -- jeremy > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor
Yes, its called datetime >>> import datetime >>> datetime.datetime.strptime('2010-10-10 01:10:00', "%Y-%m-%d %H:%M:%S") datetime.datetime(2010, 10, 10, 1, 10) >>> print datetime.datetime.strptime('2010-10-10 01:10:00', "%Y-%m-%d %H:%M:%S") 2010-10-10 01:10:00 >>> I think there are Constants that can be used in place of the formatting characters, but I couldn't find them in a quick search -- Joel Goldstick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor