Mar-01-2024, 11:16 PM
(This post was last modified: Mar-01-2024, 11:16 PM by Gribouillis.)
(Mar-01-2024, 07:25 PM)water Wrote: That seems a good method for this case, thanks.You can skip a double conversion by creating the array with
numpy.fromiter()
import datetime as dt import io import numpy as np file = io.StringIO( """\ 2024-2-27, 0:0:0 2024-2-27, 3:7:2 2024-2-27, 4:11:3 2024-2-27, 6:3:5 2024-2-27, 13:10:6 2024-2-27, 20:20:7 2024-2-27, 21:30:9 2024-2-27, 22:40:10 2024-2-27, 23:50:12 """ ) def parse(line): return dt.datetime.strptime(line, "%Y-%m-%d, %H:%M:%S\n") a = np.fromiter((parse(line) for line in file), dtype="datetime64[s]") print(a)
« We can solve any problem by introducing an extra level of indirection »