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

Question:

I am running this code to convert the sample_time variables to datetime. However, I am receiving this error: TypeError: ‘decimal.Decimal’ object cannot be interpreted as an integer.

How can I rectify this without changing my python version to an older non deprecated version?

df['sample_time'] = df['sample_time'].apply(lambda x: datetime.utcfromtimestamp(x / 1000).strftime('%Y-%m-%D %H:%M:%S'))

Dataset

Asked By: Christopher McHugh

||

Answers:

Your ‘sample_time’ column is of decimal.Decimal type. Either convert that column to float or int before processing or do that in your apply statement:

df['sample_time'] = df['sample_time'].apply(lambda x: datetime.utcfromtimestamp(float(x / 1000)).strftime('%Y-%m-%D %H:%M:%S'))
Answered By: the_strange