简体   繁体   中英

Convert time in milliseconds back to a timestamp Python?

I have a dataframe like this:

 import numpy as np
 import pandas as pd

 df_time   = pd.DataFrame({
'TIMETAG': ['13:52:41.562', '13:52:41.640', '13:52:41.749', '13:52:41.838', 
'13:52:41.948', '13:52:42.048', '13:52:42.138']})

Which has been converted to milliseconds with this command:

timetag   = pd.to_datetime(df_time['TIMETAG'])
timeit    = timetag.astype('int64')//(10**6) 

I changed the array timeit to a one with an equal spacing (100 milliseconds):

timeit_min = np.amin(timeit)
timeit_max = np.amax(timeit)

timerange = np.arange(timeit_min, timeit_max, 100)

How can I get back a timestamp - formatted as the one in the df_time - from timerange ?

熊猫可以直接处理此案

pd.to_datetime(timeit,unit='ms')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM