import pandas as pd
from geopy.distance import geodesic
# 파일 경로 설정
whether_data_path = r'C:\\Users\\ASUS\\SAI\\2023 강원산불 기상데이터.xlsx'
mountain_data_path = r'C:\\Users\\ASUS\\SAI\\가장_가까운_산_결과_2023.xlsx'
output_path = r'C:\\Users\\ASUS\\SAI\\2023 가장 가까운산 기상데티어 어쩌구.xlsx'
# 데이터 읽기
whether_data = pd.read_excel(whether_data_path)
mountain_data = pd.read_excel(mountain_data_path)
# 필요한 컬럼 이름 확인 후, 가정: 산불 데이터에 '위도', '경도', 산 데이터에 '산 이름', '위도', '경도'가 존재
whether_locations = whether_data[['발생시간','산이름','기압','기온','10m 풍속','2m 풍속', '2미터 습도']].dropna().reset_index(drop=True)
mountain_locations = mountain_data[['산불_발생시기', '가장_가까운_산']].dropna().reset_index(drop=True)
# 결과를 저장할 리스트 초기화
results = []
# 산불 위치별 가장 가까운 산 찾기
for idx, whether in whether_locations.iterrows():
when = whether['발생시간']
where = whether['산이름']
temp = None
hpa = None
air_s10 = None
air_s2 = None
suup_2 = None
for _, mountain in mountain_locations.iterrows():
if whether['발생시간'] == mountain['산불_발생시기'] :
if whether['산이름'] == mountain['가장_가까운_산'] :
air_t = whether['기온']
air_p = whether['기압']
air_s10 = whether['10m 풍속']
air_s2 = whether['2m 풍속']
suup_2 = whether['2미터 습도']
else :
continue
else :
continue
# 결과 저장
results.append({
'발생시기': when,
'발생위치' : where,
'기온' : air_t,
'기압' : air_p,
'풍속 10m': air_s10,
'풍속 2m': air_s2,
'습도 2m': suup_2
})
# 결과를 데이터프레임으로 변환
result_df = pd.DataFrame(results)
result_df.dropna(axis='index', how = 'any', inplace = True)
result_df
# 엑셀 파일로 저장
result_df.to_excel(output_path, index=False)
print(f"결과가 '{output_path}' 파일로 저장되었습니다.")