Errors in Posted Code
Corections to your code (missing parenthesis and use of X rather than x):
df['Date of Travel'].apply(lambda x:(datetime.utcfromtimestamp(0) + timedelta(days=int(x))).strftime('%d-%m-%Y'))
But this gives incorrect dates since:
- Excel 5 digit timestamp starts in 1900
- while utcfromtimestamp(0)starts in 1970
Working code
We modify the function from How to convert a given ordinal number (from Excel) to a date by Martijn Pieters to convert from 5 digit Excel to the desired date format.
from datetime import datetime, timedelta
def from_excel_ordinal(ordinal: float, _epoch0=datetime(1899, 12, 31)) -> datetime:
if ordinal >= 60:
ordinal -= 1 # Excel leap year bug, 1900 is not a leap year!
return (_epoch0 + timedelta(days=ordinal)).replace(microsecond=0).strftime('%d-%m-%Y')
Usage
df['Date of Travel'].apply(from_excel_ordinal)
Test
data = {'Date of Travel':[40055, 0, 4200]}
df = pd.DataFrame(data)
result = df['Date of Travel'].apply(from_excel_ordinal)
print(result)
Output
0 30-08-2009 # note: 40055 is Aug. 30, 2009 not March 12, 2022 as states in OP
1 31-12-1899
2 01-07-1911
Name: Date of Travel, dtype: object