我正在使用python 2.7.3
我怎样才能找到&显示每天我的txt文件的最大值
TimeStamp,Irradiance,Ambient_Temperature
21/7/2014 0:00,0.66,29.16
21/7/2014 0:00,0.71,29.16
21/7/2014 0:00,0.65,29.17
21/7/2014 0:00,0.67,29.17
21/7/2014 0:01,0.58,29.17
.
.
.
22/7/2014 23:58,0.69,28.54
22/7/2014 23:58,0.61,28.54
22/7/2014 23:58,0.65,28.51
22/7/2014 23:58,0.59,28.54
22/7/2014 23:59,0.63,28.55
22/7/2014 23:59,0.67,28.54
22/7/2014 23:59,0.68,28.56
22/7/2014 23:59,0.58,28.55
这就是我如何找到辐射和辐射的最大/最小天数。临时(不是一天)所以我怎么能像下面的代码一样大致找到一天而不是几天
long_title = ('\n Max Irrad Value: {:.2f} at {} , Min Irrad Value: {:.2f} at {}, Max AMB_TEMP Value: {:.2f} at {} , Min AMB_TEMP Value: {:.2f} at {}\n')
ax1.set_title(long_title.format(max(temp),min(temp),fontsize=16, color='green',ha='bottom'))
感谢:)
答案 0 :(得分:0)
data = {}
with open('path/to/input') as infile:
for line in infile:
line = line.strip()
date, rest = line.split(None,1)
time, irrad, temp = rest.split(',')
irrad = float(irrad)
temp = float(temp)
if time not in data:
data[time] = {'maxTemp':float('inf'), 'minTemp':float('-inf'), 'maxIrrad':float('inf'), 'minIrrad':float('-inf')}
if irrad < data[time]['minIrrad']:
data[time]['minIrrad'] = irrad
elif irrad > data[time]['maxIrrad']:
data[time]['maxIrrad'] = irrad
if temp < data[time]['minTemp']:
data[time]['minTemp'] = temp
elif temp > data[time]['maxTemp']:
data[time]['maxTemp'] = temp
data
现在包含每天的最高和最低温度和照射