我正在寻找一种将带有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')
答案 0 :(得分:2)
您可以将pandas.to_datetime
应用于整个Series
:
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')