After fetching data from Excel to Python, the dates have been fetched into python as '43422' format. How do I convert this integer to date format in python now?
Asked
Active
Viewed 84 times
1 Answers
0
You may be able to prevent this from happening in the first place when you read in the data: pd.read_excel('file.xlsx')
. Make sure that the data is properly formatted as a date before you read in the file.
If you want to convert this number to a date after you read it in, use the fact that it represents the number of days since January 1, 1900:
import datetime
d = '45422'
date = datetime.date(1900, 1, 1) + datetime.timedelta(int(d))
date
Output:
datetime.date(2024, 5, 12)

Nathaniel
- 3,230
- 11
- 18
-
This ignores the fact that Excel considers 29th February to be a valid date, which it isn't. openpyxl contains utilities for handling time and date conversion. – Charlie Clark Mar 19 '19 at 09:04