Re: [Tutor] genfromtxt and dtype to convert data to correct format
OPS! Sorry, I made a mistake on the posting. My output is in a string format as shown below. I want the 1st and 8th integers, the 3rd string which is OK as, the 2nd date and the rest time. I tried several combinations of dtype but could not get the date and time data to without the single quote -string format. [ (b'312171', '1995-07-01', b'Old', '13:37:00', '01:43:00', '04:42:00', '13:16:00', b'162', '13:19:00') (b'358237', '1993-05-25', b'Old', '12:22:00', '01:31:00', '04:16:00', '12:03:00', b'160', '12:13:00') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] genfromtxt and dtype to convert data to correct format
On 18/05/2016 14:14, Ek Esawi wrote: OPS! Sorry, I made a mistake on the posting. My output is in a string format as shown below. I want the 1st and 8th integers, the 3rd string which is OK as, the 2nd date and the rest time. I tried several combinations of dtype but could not get the date and time data to without the single quote -string format. [ (b'312171', '1995-07-01', b'Old', '13:37:00', '01:43:00', '04:42:00', '13:16:00', b'162', '13:19:00') (b'358237', '1993-05-25', b'Old', '12:22:00', '01:31:00', '04:16:00', '12:03:00', b'160', '12:13:00') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Try the following; line1 = [ (b'312171', '1995-07-01', b'Old', '13:37:00', '01:43:00', '04:42:00','13:16:00', b'162', '13:19:00')] line2 = [(b'358237', '1993-05-25', b'Old', '12:22:00', '01:31:00','04:16:00','12:03:00', b'160', '12:13:00')] item1A = line1[0][0] item1B = line1[0][7] item2A = line2[0][0] item2B = line2[0][7] print item1A, item1B print item2A, item2B -- Sydney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] genfromtxt and dtype to convert data to correct format
Thanks Sydney. The print statement prints items w/o quotation marks, but doesn't change the type. I want the datatype to be changed. I am thinking it can eb done with astructured array dtyep but have not been able to get to wort. Thanks again--EK ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] genfromtxt and dtype to convert data to correct format
On 18/05/16 14:14, Ek Esawi wrote: > OPS! Sorry, I made a mistake on the posting. My output is in a string > format as shown below. I want the 1st and 8th integers, the 3rd string > which is OK as, the 2nd date and the rest time. You will need to convert the integers manually I suspect with int(row[0]) and int(row[7]). For the dates and times, what happens if you simply remove the strftime() functions from your lambdas? Things are complicated slightly by your use of genfromtxt since it's part of numpy and not in the standard library. I have no idea what it does so there may be tricks you can do with it. > [ (b'312171', '1995-07-01', b'Old', '13:37:00', '01:43:00', '04:42:00', > '13:16:00', b'162', '13:19:00') -- 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor