TypeError: 'decimal.Decimal' object cannot be interpreted as an integer

问题描述 投票:0回答:1

我正在运行此代码以将 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'))

python dataframe datetime deprecated
1个回答
1
投票

您的“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'))
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.