如何将毫秒时间戳转换为 Python 中的正常日期?

How to convert millisecond time stamp to normal date in Python?

我有一个数据框,其中有一列的值以毫秒时间戳为单位。(df['Millisecond'])

我想要做的是将该列的所有值转换为正常日期。前任。 2017-04-27 04:55:00

您需要 python 的 datetime 包来执行此操作:

import datetime

date = datetime.datetime.fromtimestamp(milliseconds/1000.0)

date = date.strftime('%Y-%m-%d %H:%M:%S')

您可以使用 to_datetime 函数 https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html

df['Millisecond'] = pd.to_datetime(df['Millisecond'], unit='ms')