0

I have a numpy array of time which is in seconds. I use the following code to convert seconds in to timestamp

m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
for i in range(0, 24300):
   print h[i],":", m[i],":", s[i]

I need to print this timestamp values either in a csv file like( 01:05:25,01:04:60, 05:04:2) or store in a numpy array.

Thanks in advance

Dhara
  • 282
  • 1
  • 4
  • 19

1 Answers1

0

Remembering that a CSV file is what it says, just comma separated values.

You've basically already got your answer.

You might want to delimit the times with quotation marks, some csv-parsers might assume that the values need to be text strings if they aren't just simple numbers.

Here's an example python code fragment

    import time
    import datetime
    from datetime import datetime

    for i in range(10):
        d = datetime.now()
        print('"{0}:{1}:{2}",'.format(d.hour,d.minute,d.second))
        time.sleep(1)

And this outputs the following times:

"12:30:40",
"12:30:41",
"12:30:42",
"12:30:43",
Phil Ryan
  • 855
  • 1
  • 10
  • 16
  • my doubt is how to concatenate integer with a string. I use string= `h[i]` + ":" + `m[i]` + ":" + `s[i]` but it doesnt work. – Dhara May 28 '17 at 05:54
  • Maybe have a look at this answer https://stackoverflow.com/questions/19457227/how-to-print-like-printf-in-python3 – Phil Ryan May 28 '17 at 05:59