【发布时间】:2014-08-06 01:40:51
【问题描述】:
我正在使用 python 2.7.3
这是我的代码的 sn-p:
linematchregex = re.compile('(\d+/\d+ \d+:\d+), (\d+\.\d+)')
.
.
with open(r'temp.txt', 'r') as f:
f.next()
t,temp = zip(*[p for line in for p in linematchregex.findall(line)])
groups = itertools.groupby(f, lambda row row[0].split()[0])
for date, group in groups:
group = [(datetime.strptime(dt), value)
**for dt, value in group]**
during_8to5 = {len(value) for value in group
if datetime.time(8) <= dt.time() < datetime.time(17)}
.
.
.
.
long_title = {'\n Max AMB_TEMP Value: {:.2f} at {}, Min AMB_TEMP Value: {:.2f} at
{}, Mean AMB_TEMP Value: {:.2f} at {}')
ax1.set_title(long_title.format(max(group),min(group),sum(during_8to5)/len(during_8to5))
当我运行模块时,我得到 'for dt, value in group' 我得到'太多的值无法解压'
fyi,我的 txt 文件数据是:21/7/2014 0:00,0.66,29.16 那么我应该输入'split(',')',因为我的数据用逗号分隔吗? 由于我的时间是 h:m 格式,只输入 8 和 17 可以吗?
【问题讨论】: