I want to read a csv file and convert the Excel serial time value to a YYYY-MM-DD string. The file looks like this:
A B start_date
0 yes 42736
1 no 42751
2 yes 43039
The function I want to use as a converter is:
def convert_excel_time(excel_time):
return (pd.to_datetime('1900-01-01') + pd.to_timedelta(excel_time,unit='day')).strftime("%Y-%m-%d")
And I am using it like this:
data = pd.read_csv("data.csv",encoding = "ISO-8859-1",
converters={'start_date': convert_excel_time})
When using the function as a stand-alone, I get the correct result:
excel_time = 42736
In[1]: (pd.to_datetime('1900-01-01')+pd.to_timedelta(excel_time,unit='day')).strftime("%Y-%m-%d")
Out[1]: '2017-01-03'
However, if I use the function as a converter whilst reading the csv file, all my start dates are '1900-01-01'. What am I doing wrong?