我正在运行此代码以将 sample_time 变量转换为日期时间。但是,我收到此错误:TypeError: 'decimal.Decimal' object cannot be interpreted as an integer.
如何在不将我的 python 版本更改为较旧的非弃用版本的情况下纠正此问题?
df['sample_time'] = df['sample_time'].apply(lambda x: datetime.utcfromtimestamp(x / 1000).strftime('%Y-%m-%D %H:%M:%S'))
您的“sample_time”列是
decimal.Decimal
类型。在处理之前将该列转换为 float
或 int
或在您的 apply
语句中执行此操作:
df['sample_time'] = df['sample_time'].apply(lambda x: datetime.utcfromtimestamp(float(x / 1000)).strftime('%Y-%m-%D %H:%M:%S'))