Home > Software design >  create list of data time from an array
create list of data time from an array

Time:08-11

I have a weird format of date time information which is saved as a separate string. Such as,

print(time)
print(time[0])
print(type(time[0]))
print(type(time[0][0]))

[['2' '0' '2' ... '3' '2' '3']
 ['2' '0' '2' ... '4' '2' '3']
 ['2' '0' '2' ... '5' '2' '4']
 ...
 ['2' '0' '2' ... '5' '2' '7']
 ['2' '0' '2' ... '6' '2' '6']
 ['2' '0' '2' ... '7' '2' '0']]
['2' '0' '2' '2' '0' '5' '2' '1' '0' '7' '1' '3' '2' '3']
<class 'numpy.ma.core.MaskedArray'>
<class 'numpy.str_'>

The goal is to convert each row of the array into a proper DateTime format. The outcome can be both list or an array. For example,

['2' '0' '2' '2' '0' '5' '2' '1' '0' '7' '1' '3' '2' '3']

into DateTime format 20220521-07:13:23

As the original data has multiple rows, I need to loop through the array.

CodePudding user response:

suppose your list is:

l = ['2','0','2','2','0','5','2','1','0','7','1','3','2','3']

you can use:

time = [l[8 2*i] l[9 2*i] for i in range(3)]
date = ''.join(l[:8])   '- '    ':'.join(time)
print(date)

>>> 20220521- 07:13:23
  • Related