1

我从 python 的 Excel 表中读取日期和时间。日期存储为浮点数,例如日期:3/11/2003 4:03:00在 excel 中以37756.2180556. 在 python 中,我试图将这个十进制数字转换回常规日期,xlrd.xldate_as_tuple但我得到了一个错误。

def Rule_2(sheet):
x = 2
y = 0
total_rows = sheet.nrows
total_columns = sheet.ncols
while y != total_columns:
    column_name = sheet.cell(0,y).value
    if column_name == "birthday":
        while x != total_rows:
            c_val = sheet.cell(x,y).value
            date = xlrd.xldate_as_tuple(c_val, book.datemode)
            print "row:", x + 1, date
            x += 1
    y += 1

此代码产生此错误:

Traceback (most recent call last):
  File "Data Cleaner.py", line 104, in <module>
    Rule_2(sheet)
  File "Data Cleaner.py", line 31, in Rule_2
    date = xlrd.xldate_as_tuple(c_val, book.datemode)
  File "/Library/Python/2.7/site-packages/xlrd/xldate.py", line 61, in xldate_as_tuple
    xldays = int(xldate)
ValueError: invalid literal for int() with base 10: ''

关于如何解决这个问题的任何想法,或者我做错了什么?

谢谢您的帮助!

4

0 回答 0