When I try to convert from number format to Date I'm not getting the same result what I get in Excel.

I need to convert a Number to date format and get the same result what I get in Excel.

For Example in Excel for the below Number I get the following:

Input - 42970.73819

Output- 8/23/2017 17:43

I tried using the date conversion in Pandas but not getting the same result as of Excel.

Thank you

Madan

解决方案

I think you need convert serial date:

df = pd.DataFrame({'date':[42970.73819,42970.73819]})

print (df)

date

0 42970.73819

1 42970.73819

df = pd.to_datetime((df['date'] - 25569) * 86400.0, unit='s')

print (df)

0 2017-08-23 17:42:59.616

1 2017-08-23 17:42:59.616

Name: date, dtype: datetime64[ns]