I have a large dataset with unix (epoch) time that I need to convert to datetime in milliseconds. My code should do the job since I specified to return milliseconds, but somehow it only returns up to seconds. What needs to be changed?
import pandas as pd
# reading in the excel file timestamps.xlsx
# this file contains a column 'epoch' with the unix epoch timestamps
df = pd.read_excel('epoch_time.xlsx')
# translate epochs into human readable and write into newly created column
# timestamps are in ms, hence the unit
df['time'] = pd.to_datetime(df['epoch'], unit='ms')
# remove epoch row
df = df.drop('epoch', axis=1)
# write to excel file 'new_timestamps.xlsx'
# index=False prevents pandas to add the indices as a new column
df.to_excel('new_timestamps.xlsx', index=False)