Currently I'm running this below code for single record but I want run this code for all the cells in the column. Please help on this request.
from datetime import datetime
import xlrd
Date= 44774.45833333
New_date = datetime (*xlrd.xldate_as_tuple(excel_date,0))
print(New_date)
#rsult is 2022-08-01 11:00:00
Now I have a column called RETA where I want to apply this code to all the cells in this column and change the numeric format to datetime format.
sample data:
Theater | RETA TPM SLACycletime
----------------------------------------------------------
US | 2022-09-22 15:33:00 | Invalid Data
US | 44774.45833 | 558:19:30
US | 2022-09-2022 18:03:00 | 111:44:26
US | | 15:44:26
US | 1/8/2022 10:00:00 AM | Invalid Data
As you want a datetime, use
xlrd.xldate_as_datetimedirectly.The easy (but non-vectorized) answer is:
Output:
For a vectorized version, let's rewite
xlrd.xldate_as_datetime's code to work on a Series:Example with the two modes:
handling mixed formats
Output: