import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 한글 폰트 설정 (Windows 환경)
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams['font.family'] = 'Malgun Gothic'
# CSV 파일 불러오기
df_delivery = pd.read_csv('./배달_사용_통계.csv', encoding='utf-8')
df_delivery.columns = df_delivery.columns.str.strip()
df_covid = pd.read_csv('./코로나_확진자_수_통계.csv', encoding='utf-8')
df_covid.columns = df_covid.columns.str.strip()
# 데이터 병합
df = pd.merge(df_delivery, df_covid, on='연도', how='inner')
# 데이터 타입 변환 (문자열 유지)
df['연도'] = df['연도'].astype(str) # 문자열 변환
df['배달앱'] = pd.to_numeric(df['배달앱'], errors='coerce')
df['배달대행'] = pd.to_numeric(df['배달대행'], errors='coerce')
df['확진자'] = pd.to_numeric(df['확진자'], errors='coerce')
df['사망자'] = pd.to_numeric(df['사망자'], errors='coerce')
df['백신'] = pd.to_numeric(df['백신'], errors='coerce')
df['사망률 감소'] = pd.to_numeric(df['사망률 감소'], errors='coerce')
df['온라인 쇼핑'] = pd.to_numeric(df['온라인 쇼핑'], errors='coerce')
df['미세먼지'] = pd.to_numeric(df['미세먼지'], errors='coerce')
# 결측치 제거
df = df.dropna(subset=['연도', '배달앱', '배달대행'])
# 그래프 설정
fig, axes = plt.subplots(2, 2, figsize=(10, 8))
# 그래프 1: 배달앱 & 배달대행 vs 코로나 확진률
axes[0, 0].plot(df['연도'], df['확진자'], marker='o', linestyle='-', color='red', label='코로나 확진률(누적)')
axes[0, 0].plot(df['연도'], df['사망자'], marker='o', linestyle='-', color='gray', label='코로나 사망률(누적)')
axes[0, 0].plot(df['연도'], df['배달앱'], marker='o', linestyle='-', color='yellow', label='배달앱 이용률')
axes[0, 0].plot(df['연도'], df['배달대행'], marker='o', linestyle='-', color='orange', label='배달대행 이용률')
axes[0, 0].set_title('배달앱 및 배달대행과 코로나의 관계')
axes[0, 0].set_ylabel('비율 (%)')
axes[0, 0].grid()
axes[0, 0].legend()
# 그래프 2: 코로나 백신과 사망률 감소 효과
axes[0, 1].plot(df['연도'], df['확진자'], marker='o', linestyle='-', color='red', label='코로나 확진률(누적)')
axes[0, 1].plot(df['연도'], df['사망자'], marker='o', linestyle='-', color='gray', label='코로나 사망률(누적)')
axes[0, 1].plot(df['연도'], df['백신'], marker='o', linestyle='-', color='cyan', label='코로나 백신 접종률(누적)')
axes[0, 1].plot(df['연도'], df['사망률 감소'], marker='o', linestyle='-', color='orchid', label='예상 사망률 감소율')
axes[0, 1].set_title('코로나 발생과 백신 효과 분석')
axes[0, 1].set_ylabel('비율 (%)')
axes[0, 1].grid()
axes[0, 1].legend()
# 그래프 3: 코로나 확진율과 온라인 쇼핑 증가
axes[1, 0].plot(df['연도'], df['확진자'], marker='o', linestyle='-', color='red', label='코로나 확진률(누적)')
axes[1, 0].plot(df['연도'], df['사망자'], marker='o', linestyle='-', color='gray', label='코로나 사망률(누적)')
axes[1, 0].plot(df['연도'], df['온라인 쇼핑'], marker='o', linestyle='-', color='sandybrown', label='온라인 쇼핑 증가율')
axes[1, 0].set_title('코로나와 온라인 쇼핑의 관계')
axes[1, 0].set_ylabel('비율 (%)')
axes[1, 0].grid()
axes[1, 0].legend()
# 그래프 4: 코로나 확진율과 미세먼지 농도 변화
axes[1, 1].plot(df['연도'], df['확진자'], marker='o', linestyle='-', color='red', label='코로나 확진률(누적)')
axes[1, 1].plot(df['연도'], df['사망자'], marker='o', linestyle='-', color='gray', label='코로나 사망률(누적)')
axes[1, 1].plot(df['연도'], df['미세먼지'], marker='o', linestyle='-', color='tan', label='미세먼지 평균 농도')
axes[1, 1].set_title('코로나와 미세먼지의 관계')
axes[1, 1].set_ylabel('비율 (%)')
axes[1, 1].grid()
axes[1, 1].legend()
# x축 레이블 설정
for ax in axes.flat:
ax.set_xticks(range(len(df["연도"])))
ax.set_xticklabels(df["연도"], rotation=45)
plt.tight_layout()
plt.show()
# 바 그래프 설정
bar_width = 0.15
index = range(len(df["연도"])) # x축 인덱스 생성
fig, axes = plt.subplots(2, 2, figsize=(10, 8))
# 그래프 1: 배달앱 & 배달대행 vs 코로나 확진률
axes[0, 0].bar(index, df["확진자"], bar_width, label="코로나 확진률(누적)", color="red")
axes[0, 0].bar([i + bar_width for i in index], df["사망자"], bar_width, label="코로나 사망률(누적)", color="gray")
axes[0, 0].bar([i - bar_width * 2 for i in index], df["배달앱"], bar_width, label="배달앱 이용률", color="yellow")
axes[0, 0].bar([i - bar_width for i in index], df["배달대행"], bar_width, label="배달대행 이용률", color="orange")
axes[0, 0].set_title('배달앱 및 배달대행과 코로나의 관계')
axes[0, 0].set_ylabel('비율 (%)')
axes[0, 0].grid()
axes[0, 0].legend()
# 그래프 2: 코로나 백신과 사망률 감소 효과
axes[0, 1].bar(index, df["확진자"], bar_width, label="코로나 확진률(누적)", color="red")
axes[0, 1].bar([i + bar_width for i in index], df["사망자"], bar_width, label="코로나 사망률(누적)", color="gray")
axes[0, 1].bar([i - bar_width for i in index], df["백신"], bar_width, label="백신 접종률(누적)", color="cyan")
axes[0, 1].bar([i - bar_width * 2 for i in index], df["사망률 감소"], bar_width, label="사망률 감소율", color="orchid")
axes[0, 1].set_title('코로나 발생과 백신 효과 분석')
axes[0, 1].set_ylabel('비율 (%)')
axes[0, 1].grid()
axes[0, 1].legend()
# 그래프 3: 코로나 확진율과 온라인 쇼핑 증가
axes[1, 0].bar(index, df["확진자"], bar_width, label="코로나 확진률(누적)", color="red")
axes[1, 0].bar([i + bar_width for i in index], df["사망자"], bar_width, label="코로나 사망률(누적)", color="gray")
axes[1, 0].bar([i - bar_width for i in index], df["온라인 쇼핑"], bar_width, label="작년 대비 온라인 쇼핑 거래액 증가율", color='salmon')
axes[1, 0].set_title('코로나와 온라인 쇼핑의 관계')
axes[1, 0].set_ylabel('비율 (%)')
axes[1, 0].grid()
axes[1, 0].legend()
# 그래프 4: 코로나 확진율과 미세먼지 농도 변화
axes[1, 1].bar(index, df["확진자"], bar_width, label="코로나 확진률(누적)", color="red")
axes[1, 1].bar([i + bar_width for i in index], df["사망자"], bar_width, label="코로나 사망률(누적)", color="gray")
axes[1, 1].bar([i - bar_width for i in index], df["미세먼지"], bar_width, label="평균 미세먼지 농도", color='tan')
axes[1, 1].set_title('코로나와 미세먼지의 관계')
axes[1, 1].set_ylabel('비율 (%)')
axes[1, 1].grid()
axes[1, 1].legend()
# x축 레이블 설정
for ax in axes.flat:
ax.set_xticks(index)
ax.set_xticklabels(df["연도"], rotation=45)
plt.tight_layout()
plt.show()
# 데이터 병합
df = pd.merge(df_delivery, df_covid, on='연도', how='inner')
# 날짜 데이터를 처리 (문자열 → 연도 숫자로 변환)
df['연도'] = df['연도'].astype(str).str[:4].astype(int) # '2017-01' → 2017
# 숫자로 변환 가능한 열 변환
numeric_cols = ['배달앱', '배달대행', '확진자', '사망자', '백신', '사망률 감소', '온라인 쇼핑', '미세먼지']
df[numeric_cols] = df[numeric_cols].apply(pd.to_numeric, errors='coerce')
# 결측치 제거
df = df.dropna()
# 히트맵을 위한 숫자형 데이터만 선택
df_numeric = df.select_dtypes(include=['number'])
# 히트맵 생성
plt.figure(figsize=(10, 8))
sns.heatmap(df_numeric.corr(), annot=True, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("데이터 간 상관 관계 히트맵")
plt.show()




😱🥶
좋아요! 흔한 코로나 데이터가 아닌, 조금 더 유니크하고 흥미로운 분석이 가능한 데이터를 찾아볼게요.
🌀 코로나의 유니크한 영향 & 데이터 아이디어
✔️ '코로나 반려동물 붐' 분석 → 팬데믹 이후 반려동물 입양률 증가
✔️ '틱톡 사용량 증가' 데이터 → 코로나 이후 SNS 이용 패턴 변화
✔️ '코로나 이후 미용실 방문 횟수 변화' → 자가 헤어컷 vs 미용실 방문 감소
✔️ '초콜릿 소비 증가 vs 건강 식품 소비 변화' → 스트레스 증가로 단 음식 소비 증가
✔️ '코로나 이후 이혼율 변화' → 팬데믹 기간 동안 결혼 vs 이혼 트렌드 분석
✔️ '야외 캠핑과 차박 증가 데이터' → 해외여행 제한 후 국내 여행 패턴 변화
✔️ '운동 관련 앱 다운로드 추이' → 헬스장 폐쇄 이후 홈트렌드 급성