簡體   English   中英

UNIX時間到人類可讀時間的快速轉換

[英]Fast convertions of UNIX time to human readable time

我正在尋找一種將帶有UNIX時間戳的列轉換為人類可讀時間的快速方法。 目前,我正在使用以下代碼:

#convert unix to human readable form
for i in range(len(df)):
    #df.timestamp[i] = str(pd.to_datetime(df.timestamp  [i],unit='s'))
    df.timestamp[i] = datetime.utcfromtimestamp(int(df.timestamp[i])).strftime('%Y-%m-%d %H:%M:%S')

您可以將pandas.to_datetime應用於整個Series

df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM