我正在以这种方式解析文件:
for d in csvReader:
print datetime.datetime.strptime(d["Date"]+"-"+d["Time"], "%d-%b-%Y-%H:%M:%S.%f").date()
date() 返回:2000-01-08,这是正确的
time() 返回:06:20:00,这也是正确的
我将如何返回诸如“日期+时间”或“日期+小时+分钟”之类的信息
编辑
对不起,我应该更精确,这是我想要实现的目标:
lmb = lambda d: datetime.datetime.strptime(d["Date"]+"-"+d["Time"], "%d-%b-%Y-%H:%M:%S.%f").date()
daily_quotes = {}
for k, g in itertools.groupby(csvReader, key = lmb):
lowBids = []
highBids = []
openBids = []
closeBids = []
for i in g:
lowBids.append(float(i["Low Bid"]))
highBids.append(float(i["High Bid"]))
openBids.append(float(i["Open Bid"]))
closeBids.append(float(i["Close Bid"]))
dayMin = min(lowBids)
dayMax = max(highBids)
open = openBids[0]
close = closeBids[-1]
daily_quotes[k.strftime("%Y-%m-%d")] = [dayMin,dayMax,open,close]
如您所见,现在我按天对值进行分组,我想按小时(我需要 date + hour )或分钟( date + hour + minute )对它们进行分组
提前致谢 !