파이썬 반복분 출력
조회수 120회
for year in range(1943,1945):
for month in range(1, 13):
# 각 월에 해당하는 마지막 일자 계산
if month in [1, 3, 5, 7, 8, 10, 12]:
last_day = 31
elif month == 2:
last_day = 29
else:
last_day = 30
# 월별로 일자 값을 바꿔가며 필터링하여 평균값 계산
for day in range(1, last_day+1):
filtered_df = df[(df['Month'] == month) & (df['Day'] == day)]
filter_df = df[(yeosu_data['Year'] == year) & (df['Month'] == month) & (df['Day'] == day)]
final_temperature = filter_df['Temperature'].tolist()
avg_temperature = filtered_df['Temperature'].mean()
# 결과를 리스트에 저장
result_list.append({'월': month, '일': day, '기온(K) 평균': final_temperature})
result_list
기온 평균의 값이 정수가 나오도록 하고 싶은데 final_temperature = filter_df['Temperature'].tolist()[0]
을 하면 다음과 같은 오류가 발생합니다.
list index out of range
어떻게 해야 오류를 해결할 수 있을까요?
댓글 입력