[Tutor] genfromtx- date and time conversions

Alan Gauld alan.gauld at btinternet.com
Sun Feb 14 04:06:16 EST 2016


On 14/02/16 03:53, Ek Esawi wrote:

> genfromtxt. I have 2 questions: (1) Is there a function (method) to convert
> time in H:M:S, format, e.g. 12:30:30 to decimal or 24 format e.g.12.508 

The decimal format is not a common one but the best place to start
are the time and datetime (and calendar modules for leap years)
in the standard library. They will make writing your own
converter easier.

For time handling the time modsule includes the strptime/strftime
functions which can read/write string representations of times.

> writing my own function to convert it ? (2) Given a date of the form
> 12/20/2005, can such date in such format be converted with converters in
> numpy using datetime to ‘2005-20-15’? I had to reformat the date on my csv
> file to the later form for python to read it correctly.

strptime/strftime can do that for you. You might find the
datetime module versions of the functions more convenient
for dates.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list