我有,我一直給一組數據如下數據集內尋找最大值給出限制
Station1.txt樣品#different套不同的沒有數據的任務。站
Date Temperature
19600101 46.1
19600102 46.7
19600103 99999.9 #99999 = not recorded
19600104 43.3
19600105 38.3
19600106 40.0
19600107 42.8
我試圖創建一個函數 display_maxs(stations, dates, data, start_date, end_date)
其顯示 最高溫度爲給定的站/ s和給定日期範圍 的表。例如:
stations = load_stations('stations2.txt')
5
data = load_all_stations_data(stations)
dates = load_dates(stations)
display_maxs(stations, dates, data, '20021224','20021228' #these are date yyyy/mm/dd)
我創建功能數據
def load_all_stations_data(stations):
data = {}
file_list = ("Brisbane.txt", "Rockhampton.txt", "Cairns.txt", "Melbourne.txt", "Birdsville.txt", "Charleville.txt"))
for file_name in file_list:
file = open(stations(), 'r')
station = file_name.split()[0]
data[station] = []
for line in file:
values = line.strip().strip(' ')
if len(values) == 2:
data[station] = values[1]
file.close()
return data
功能站
def load_all_stations_data(stations):
stations = []
f = open(stations[0] + '.txt', 'r')
stations = []
for line in f:
x = (line.split()[1])
x = x.strip()
temp.append(x)
f.close()
return stations
和功能日期
def load_dates(stations):
f = open(stations[0] + '.txt', 'r')
dates = []
for line in f:
dates.append(line.split()[0])
f.close()
return dates
現在我只需要幫助創造桌子whi ch顯示任何給定日期限制的最大溫度,並用數據,日期和工作站調用上述功能。
實際上在文件中是否存在'#99999 = not recorded',或者您是否僅僅爲了我們的利益而添加了這些內容? – TheBlackCat