I am quite new to python and trying some features. I searched a lot in here for a possible solution with no success. This is my issue:
Goal:
read a column with date and time from an .xlsx file --> works
get this column in a numpy array --> works
The array item is read from the .xlsx as an Object
The array output looks like this:
['2020-11-09 20:30:59' '2020-11-08 09:22:54' '2020-11-04 02:24:17' ...
'1900-01-27 02:30:00' '1900-01-24 03:00:00' '1900-01-18 15:30:00']
- convert the date and time to a float --> does not work
I tried the following:
x[:, 0] = [np.datetime64(x[:, 0])]
--> this doesn't work; so I tried to convert to String before.
x[:, 0] = [np.datetime64(str(x[:, 0]))]
--> This does also not work with this error message:
ValueError: Error parsing datetime string "['2020-11-09 20:30:59' '2020-11-08 09:22:54' '2020-11-04 02:24:17' ...
'1900-01-27 02:30:00' '1900-01-24 03:00:00' '1900-01-18 15:30:00']" at position 0
So where is the issue?
Thanks a lot for the answer! It seems to work with the datetime64 conversion. I did change .
np.array(alist, 'datetime64[ms]')
to
np.array(alist, 'datetime64[ns]')
By that I get the datetime64 as an integer. Nevertheless, how comes that I get negative values for the early datesas seen in the output?
-----------------------------------------------------
--> Before conversion: ['2020-11-09 20:30:59' '2020-11-08 09:22:54' '2020-11-04 02:24:17' ...
'1900-01-27 02:30:00' '1900-01-24 03:00:00' '1900-01-18 15:30:00']
-----------------------------------------------------
--> After conversion to dt64: [1604953859000000000 1604827374000000000 1604456657000000000 ...
-2206733400000000000 -2206990800000000000 -2207464200000000000]
-----------------------------------------------------