본문 바로가기
Project Jupyter

Project Jupyter(기온 공공데이터)-2024-06-14

by 앵보몬 2024. 6. 14.
728x90
반응형

2023년 8월 1일 ~ 31일 (8월)최고기온 합계 및 평균구하기

f = open('seoul1.csv')
data = csv.reader(f)
header = next(data)

start_date = '2023-08-01'
end_date = '2023-08-31'
total_temp1 = 0
count = 0

for row in data:
    if row[0] >= start_date and row[0] <= end_date:
        total_temp1 += float(row[2])
        count += 1

average_temp = (total_temp1) / count
print(f"최고기온 합계 : {total_temp1}")
print(f"최고기온 평균 : {round(average_temp,1)}")

 

(1980년 12월 1일 ~ 1978년 12월 1일) 평균기온

f = open('seoul1.csv')
data = csv.reader(f)
header = next(data)

start_date = '1978-12-01'
end_date = '1980-12-01'
total_temp1 = 0
total_temp2 = 0

for row in data:
    if row[0] == start_date:
        total_temp1 += float(row[2])
    elif row[0] == end_date:
        total_temp2 += float(row[2])

average_temp = (total_temp1 + total_temp2) / 2
print(f"{start_date}~{end_date}의 평균기온 : {average_temp : .1f}℃")

 

(2012년 1월 1일 ~ 12월 31일) 최처 기온 날짜 구하기

import csv
f = open('seoul1.csv')
data = csv.reader(f)
header = next(data)

start_date = '2012-01-01'
end_date = '2012-12-31'

min_temp = 0
min_date = 0
temp = 0

for row in data :
    if row[0] >= start_date and row[0] <= end_date:
        temp = float(row[-1])
        if temp < min_temp:
            min_temp = temp
            min_date = row[0]


print("기상 관측 이래 서울의 최저 기온이 가장 높았던 날 : ", {min_date})
print(f"최저기온 : {min_temp : .1f}℃")

 

seoul1.csv
1.19MB

728x90
반응형