2

I am doing some data analysis on a public dataset ( an excel file ), yet when I use the pandas pd.todatetime, the conversion is wrong.

# Converting date column from integer to datetime
 Transactions['product_first_sold_date'] = 
 pd.to_datetime(Transactions['product_first_sold_date'], unit='s')

Transactions['product_first_sold_date'].head()

Result :

0   1970-01-01 11:27:25
1   1970-01-01 11:35:01
2   1970-01-01 10:06:01
3   1970-01-01 10:02:25
4   1970-01-01 11:43:46
Name: product_first_sold_date, dtype: datetime64[ns]

yet when I try to do the conversion with excel the dates are different, and seem right somehow

Original column rows :

41245.00
41701.00
36361.00
36145.00
42226.00

After conversion with Excel:

2012-12-02
2014-03-03
1999-07-20
1998-12-16
2015-08-10

Briefly , what I want is the dates like I converted them with Excel because they make more sense.

  • please no images, use reproducible code as **text**. – mozway Jul 24 '22 at 16:49
  • 1
    This seems to answer your question: https://stackoverflow.com/questions/29387137/how-to-convert-a-given-ordinal-number-from-excel-to-a-date, and specifically the accepted answer [here](https://stackoverflow.com/a/29387450/18135454) – constantstranger Jul 24 '22 at 17:04

0 Answers0