RPA- conversion processing method when using Excel Python read date results in a number

Do not know if you have never met before, when reading the ranks or Excel cells using Python, if its content is the date format, and the date is not printed, but a string of numbers, as shown below:

 

 


We look forward to this date is parsed: 2019/11/20 1919/1/20 well, and the result is a digital 6960.0 and 43789.0, which is what causes it? What this number is it?
In fact, this is the origin in 1900, to the date specified number of days elapsed.

Want to convert the digital date, by a method xldate_as_tuple xlrd may be converted to a digital date, add code in the code block conversion, the following reference code:

from datetime Import datetime
 from to xlrd Import xldate_as_tuple 

ExcelDate = []
 for DATE in lv_1:
 Print ( ' Digital Date: ' , DATE, End = '  ' ) 
NEW_DATE = STR (datetime (* xldate_as_tuple (DATE, 0))) # use xldate_as_tuple the method of conversion, and the converted value becomes string type 
Print ( ' the converted date: ' , NEW_DATE) 
NEW_DATE = NEW_DATE [0:10] # take part date 
Print ( " the final print: ', NEW_DATE) 

ExcelDate.append (NEW_DATE) 

Print ( ' date list of the resulting ' , ExcelDate)

 


effect:

 

 


Of course, if the pandas library to read Excel will not encounter this situation, the Excel [read] components use is read_excel method pandas are:

 

 

 

 

 Free Trial: https://support.i-search.com.cn/

Guess you like

Origin www.cnblogs.com/isearch/p/11897803.html