Python Forum
[Numpy] Load date/time from .txt to 'datetime64' type.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Numpy] Load date/time from .txt to 'datetime64' type.
#1
I have date/time data in .txt file likes below format:
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
I want to load that use numpy.loadtxt() and convert to 'datetime64' type, but 'datetime64' type require string format likes below:
numpy.array(['2020-02-27T15:23:07'], dtype = 'datetime64[s]')
so I must fill some '0', and concatenate date and time use 'T'?

# fill '0'
2024-02-27, 00:00:00
2024-02-27, 03:07:02
2024-02-27, 04:11:03
2024-02-27, 06:03:05
2024-02-27, 13:10:06
2024-02-27, 20:20:07
2024-02-27, 21:30:09
2024-02-27, 22:40:10
2024-02-27, 23:50:12

# concatenate use 'T'
2024-02-27T00:00:00
2024-02-27T03:07:02
2024-02-27T04:11:03
2024-02-27T06:03:05
2024-02-27T13:10:06
2024-02-27T20:20:07
2024-02-27T21:30:09
2024-02-27T22:40:10
2024-02-27T23:50:12
Is it have simply way to do that?
Reply


Messages In This Thread
[Numpy] Load date/time from .txt to 'datetime64' type. - by water - Mar-01-2024, 08:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 867 Mar-26-2024, 02:18 PM
Last Post: snippsat
  GroupBy - Sum = Error [datetime64 type does not support sum operations] BSDevo 4 3,378 Oct-27-2023, 07:22 PM
Last Post: BSDevo
  Pandas read csv file in 'date/time' chunks MorganSamage 4 1,806 Feb-13-2023, 11:24 AM
Last Post: MorganSamage
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,744 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  Does a pandas have a date without a time? AlekseyPython 6 5,056 Feb-10-2021, 09:24 AM
Last Post: Naheed
  How to fill datetime64 field in numpy structured array? AlekseyPython 0 2,349 Oct-20-2020, 08:17 AM
Last Post: AlekseyPython
  How to prepare a NumPy array which include float type array elements subhash 0 1,961 Mar-02-2020, 06:46 AM
Last Post: subhash
  replace nan values by mean group by date.year, date.month wissam1974 5 8,643 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Problem with date type (object to datetime) karlito 6 3,737 Oct-16-2019, 08:07 AM
Last Post: karlito
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 3,074 Apr-09-2019, 04:54 PM
Last Post: PhysChem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020