관리 메뉴

열심히 일한 당신 떠나라

2024년 2월 강수량 본문

일상생활

2024년 2월 강수량

@thiskorea 2024. 2. 26. 14:36

2024년 2월은 비가 참 많이 왔습니다. 청주 지역은 중부 지방임에도 불구하고 눈은 거의 오지 않고 비만 계속 왔습니다. 2월 25일까지 얼마나 비가 내렸는지 확인해 볼까요?

import pandas as pd

# 강수량 데이터를 불러옵니다.
data_path_precipitation = '/content/drive/MyDrive/데이터분석/cj_precipitation.csv'

# pandas를 사용하여 데이터를 로드합니다.
df_precipitation = pd.read_csv(data_path_precipitation, encoding='CP949')

# 데이터가 잘 로드되었는지 확인합니다.
df_precipitation.head(), df_precipitation.tail()

앞서 작성한 블로그에서 기상청 데이터 다운로드 방법은 확인할 수 있습니다.

https://ax7taehun.tistory.com/138

 

기후 변화의 증거(청주 기온)

본업으로 돌아가본다. 지금 저는 인공지능중심고에서 인공지능을 가르치고 있는 정보교사입니다. '식량위기대한민국(남재작)'을 읽고 있는 중에 이 문구가 궁금해졌습니다. 우리가 오해하는 것

ax7taehun.tistory.com

우선 다른 해에도 비가 이렇게 많이 온 적이 있을까? 

# 데이터를 datetime 객체로 변환합니다.
df_precipitation['date'] = pd.to_datetime(df_precipitation['date'])

# 강수량 데이터가 NaN인 경우를 0으로 처리합니다.
df_precipitation['precipitation'].fillna(0, inplace=True)

# 2월의 연도별 강수량 데이터를 준비합니다.
feb_precipitation_by_year = df_precipitation\
[df_precipitation['date'].dt.month == 2].\
groupby(df_precipitation['date'].dt.year)['precipitation'].sum()

# 2024년 2월 강수량과 비교할 수 있는 수치인지 확인합니다.
precipitation_feb_2024 = feb_precipitation_by_year[2024]

print(f'2월에 가장 비가 많이 온 연도는 {feb_precipitation_by_year.idxmax()}년입니다.\n\
그 해 강수량은 {feb_precipitation_by_year.max()}mm이고,\n\
2024년 2월 강수량은 {precipitation_feb_2024}mm입니다.')

2월에 가장 비가 많이 온 연도는 1990년입니다. 그 해 강수량은 99.2mm이고, 2024년 2월 강수량은 79.0mm입니다.

코드를 실행해 보니 1990년 2월에 비가 참 많이 왔네요. 기상청 자료를 확인한 결과 평년 강수량이 27.5~44.9㎜정도니까 2024년 2월이 엄청 많이 내린 것은 맞습니다. 1990년에도 99.2mm가 왔으니 2024년보다 많이 온 게 확인이 되네요.

import matplotlib.pyplot as plt

# 데이터를 datetime 객체로 변환합니다.
df_precipitation['date'] = pd.to_datetime(df_precipitation['date'])

# 강수량 데이터가 NaN인 경우를 0으로 처리합니다.
df_precipitation['precipitation'].fillna(0, inplace=True)

# 2월의 연도별 강수량 데이터를 준비합니다.
feb_precipitation_by_year = df_precipitation[df_precipitation['date'].dt.month == 2].groupby(df_precipitation['date'].dt.year)['precipitation'].sum()

# 2월 강수량 시각화
plt.figure(figsize=(14, 7))
feb_precipitation_by_year.plot(kind='bar', color='skyblue', edgecolor='black')
plt.title('February Precipitation by Year')
plt.xlabel('Year')
plt.ylabel('Precipitation (mm)')
plt.grid(True, linestyle='--', alpha=0.7)
plt.show()

연도별 2월 강수량

비가 온 날을 세어보겠습니다.

# 비가 온 날을 카운트합니다. 여기서는 강수량이 0보다 큰 날을 비가 온 날로 가정합니다.
rainy_days_by_year = df_precipitation[df_precipitation['precipitation'] > 0].groupby(df_precipitation['date'].dt.year).size()

# 2월에 해당하는 데이터만 필터링합니다.
rainy_days_feb_by_year = df_precipitation[(df_precipitation['precipitation'] > 0) & (df_precipitation['date'].dt.month == 2)].groupby(df_precipitation['date'].dt.year).size()

# 2월의 비가 온 날짜 카운트 시각화
plt.figure(figsize=(14, 7))
rainy_days_feb_by_year.plot(kind='bar', color='lightblue', edgecolor='black')
plt.title('Number of Rainy Days in February by Year')
plt.xlabel('Year')
plt.ylabel('Number of Rainy Days')
plt.grid(True, linestyle='--', alpha=0.7)
plt.show()

연도별 비 온 날

비 온 날을 세보니 역대급으로 비가 많이 온 건 확인할 수 있네요. 25중에 12일이 비가 왔으니 말이죠.