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?
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)