Python从Excel文件中读取datestring

我有excel文件中的数据与列A作为date时间string和列B与数据。 我想读取Python中的excel文件并创build两个元素的字典。 第一个是date时间vector,第二个是数据。

Excel文件中的数据看起来如下所示:

DateTime Marks 1/1/10 23:00 38.86 2/1/10 12:00 36.19 1/1/10 13:00 35.10 1/1/10 14:00 39.87 5/1/10 15:00 39.48 1/1/10 16:00 38.64 1/1/10 17:00 39.19 

我写了以下片段开始:

 import xlrd import os.path wb = xlrd.open_workbook(os.path.join('C:\Users\JD\Documents\RandomNumber','DateTimeData.xlsx')) 

但我不知道下一步该做什么?

 import os import xlrd import datetime excel = os.path.join(os.getcwd(), 'test.xlsx') book = xlrd.open_workbook(excel, 'r') data = book.sheet_by_name('Sheet1') for row in range(data.nrows)[1:]: excel_date = data.row_values(rowx=row)[0] print datetime.datetime(* xlrd.xldate_as_tuple(excel_date, datemode=0)) 

无论如何,这是一个提示。 使用for循环来parsing文件。

 datetime=[] data=[] for line in wb: datetime=line.split()[0:2] data=line.split().pop() strdate=' '.join(datetime) if 'DateTime' not in strdate: print strdate print data 

这会打印date/时间和数据。 希望这可以帮助。