When using to_datetime method of Pandas Dataframe to convert a Unix Timestamp to a Formatted DateTime in a column of data collected from a Data Logger I get the wrong year by 20 years. I have checked this post and many others but found no reason.
In a Pandas Dataframe Column I have a series of values which are Unix Timestamps. Using an online Epoch converter the Timestamps give the correct date and time, but using the to_datetime function in Pandas the year is 20 years out. The years should be 2024. Everything else is correct.Using the code:
df['WS_knot_TMx'] = pd.to_datetime(df['WS_knot_TMx'], unit='s')
The TimeStamp value is converted using the to_datetime method giving the result as shown below:
1073924220 2004-01-12 16:17:001073924690 2004-01-12 16:24:501073924790 2004-01-12 16:26:30
But the years are 20 years out.OK I can add 20 years like so:
df['WS_knot_TMx'] = df['WS_knot_TMx'].apply(lambda x: x - timedelta(days=365.25*20))
But this in a bit of a hack. Why is the conversion 20 years out?