아파트 매매가격 지수와 아파트 재고 수의 상관관계 분석: 파이썬으로 데이터 시각화하기
부동산 시장에서 아파트 재고 수와 아파트 매매가격 지수는 시장 상황을 이해하는 핵심 지표입니다. 두 지표 간의 관계를 분석하면 수요와 공급의 상호작용뿐만 아니라 경제적 요인도 파악할 수 있습니다.
이번 포스트에서는 파이썬을 활용하여 2000년부터 2023년까지의 아파트 재고와 매매가격 지수 데이터를 시각화하고, 두 변수 간의 상관관계를 분석하는 방법을 소개합니다. 분석과 그래프를 통해 부동산 시장의 주요 트렌드와 인사이트를 확인할 수 있습니다.
1. 데이터 개요 및 정의
아파트 재고 수
- 한 가구가 살 수 있도록 지어진 아파트의 수를 나타냅니다.
- 요건: 영구건물, 한 개 이상의 방과 부엌, 독립된 출입구, 관습상 소유 또는 매매 단위 등의 조건을 갖춘 아파트.
- 출처: 통계청,「주택총조사」
아파트 매매가격 지수
- 기준 시점(2021년 6월)의 주택매매가격을 100으로 설정한 가격 지수입니다.
- 해석
- 지수가 100보다 높으면 기준 시점 대비 가격 상승.
- 지수가 100보다 낮으면 기준 시점 대비 가격 하락.
- 출처: 한국감정원,「전국주택가격동향조사」
2. 데이터 테이블
아파트 재고 수 (2000-2022)
| 연도 | ’00 | ’05 | ’10 | ’15 | ’16 | ’17 | ’18 | ’19 | ’20 | ’21 | ’22 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 재고 수 (호) | 5,479,828 | 6,962,689 | 8,576,013 | 9,806,062 | 10,029,644 | 10,375,363 | 10,826,044 | 11,287,048 | 11,661,851 | 11,948,544 | 12,268,973 |
아파트 매매가격 지수 (2014-2023)
| 연도 | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 |
|---|---|---|---|---|---|---|---|---|---|---|
| 지수 | 80.9 | 84.2 | 86.1 | 87.1 | 87.8 | 86.2 | 88.9 | 100.0 | 106.0 | 92.7 |
3. 시각화 및 분석
아파트 재고 수 추세 분석 (2000-2022)

- 2000년 약 5.48M에서 2022년 약 12.27M으로 약 두 배 증가.
- 특히 2010년 이후 재고 증가 속도가 빨라졌습니다.
아파트 매매가격 지수 추세 분석 (2014-2023)

- 2014년 80.9에서 2022년 최고점(106)에 도달 후, 2023년에는 지수 92.7로 하락했습니다.
- 금리 인상과 경기 둔화로 인한 하락 가능성이 높습니다.
4. 상관관계 분석
상관관계 산점도

- 상관계수 0.82로 아파트 재고와 매매가격 지수 간 강한 양의 상관관계를 보여줍니다.
- p-value는 0.0136으로 통계적으로 유의미하며, 두 변수 간의 관계가 우연이 아님을 시사합니다.
상관행렬 히트맵

- 히트맵에서 두 변수 간의 상관계수(0.82)가 명확히 나타납니다.
5. 전체 파이썬 코드
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy import stats
# Data creation
apartment_stock = pd.DataFrame({
'year': [2000, 2005, 2010, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022],
'stock': [5479828, 6962689, 8576013, 9806062, 10029644, 10375363, 10826044, 11287048, 11661851, 11948544, 12268973]
})
price_index = pd.DataFrame({
'year': [2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023],
'index': [80.9, 84.2, 86.1, 87.1, 87.8, 86.2, 88.9, 100.0, 106.0, 92.7]
})
# Create figure with subplots
plt.figure(figsize=(12, 12))
# 1. Apartment Stock Trend
plt.subplot(2, 1, 1)
plt.plot(apartment_stock['year'], apartment_stock['stock'], marker='o', linewidth=2, color='#3498db')
plt.title('Apartment Stock Trend (2000-2022)', pad=15, fontsize=14)
plt.xlabel('Year', fontsize=12)
plt.ylabel('Number of Units', fontsize=12)
plt.gca().yaxis.set_major_formatter(plt.FuncFormatter(lambda x, p: format(int(x/1000000), ',') + 'M'))
plt.grid(True, linestyle='--', alpha=0.7)
plt.xticks(rotation=45)
# Add value labels
for x, y in zip(apartment_stock['year'], apartment_stock['stock']):
plt.annotate(f'{y:,.0f}',
(x, y),
textcoords="offset points",
xytext=(0,10),
ha='center',
fontsize=8)
# 2. Price Index Trend
plt.subplot(2, 1, 2)
plt.plot(price_index['year'], price_index['index'], marker='o', color='#e74c3c', linewidth=2)
plt.title('Apartment Price Index Trend (2014-2023)', pad=15, fontsize=14)
plt.xlabel('Year', fontsize=12)
plt.ylabel('Price Index (2021.6=100)', fontsize=12)
plt.grid(True, linestyle='--', alpha=0.7)
plt.xticks(rotation=45)
# Add value labels
for x, y in zip(price_index['year'], price_index['index']):
plt.annotate(f'{y:.1f}',
(x, y),
textcoords="offset points",
xytext=(0,10),
ha='center',
fontsize=8)
plt.tight_layout()
plt.show()
# Correlation Analysis
# Merge datasets for overlapping years
merged_data = pd.merge(apartment_stock, price_index, on='year', how='inner')
merged_data.columns = ['Year', 'Stock', 'Price_Index']
# Create correlation visualization
plt.figure(figsize=(15, 5))
# 1. Scatter plot with regression line
plt.subplot(1, 2, 1)
sns.regplot(x='Stock', y='Price_Index', data=merged_data, color='#2ecc71')
plt.title('Stock vs Price Index Correlation', pad=15, fontsize=14)
plt.xlabel('Number of Units', fontsize=12)
plt.ylabel('Price Index', fontsize=12)
plt.gca().xaxis.set_major_formatter(plt.FuncFormatter(lambda x, p: format(int(x/1000000), ',') + 'M'))
# Calculate correlation coefficient and p-value
correlation_coefficient, p_value = stats.pearsonr(merged_data['Stock'], merged_data['Price_Index'])
# Add correlation information to plot
plt.text(0.05, 0.95, f'Correlation: {correlation_coefficient:.2f}\np-value: {p_value:.4f}',
transform=plt.gca().transAxes,
fontsize=10,
verticalalignment='top')
# 2. Heatmap of correlation matrix
plt.subplot(1, 2, 2)
correlation_matrix = merged_data[['Stock', 'Price_Index']].corr()
sns.heatmap(correlation_matrix,
annot=True,
cmap='coolwarm',
vmin=-1,
vmax=1,
center=0,
fmt='.2f',
square=True)
plt.title('Correlation Matrix Heatmap', pad=15, fontsize=14)
plt.tight_layout()
plt.show()6. 코드 상세 해설
1. 데이터 생성
apartment_stock = pd.DataFrame({...}) price_index = pd.DataFrame({...})
apartment_stock: 2000년부터 2022년까지의 아파트 재고 데이터를 생성.price_index: 2014년부터 2023년까지의 매매가격 지수 데이터를 생성.2. 시각화
아파트 재고 추세
plt.subplot(2, 1, 1) plt.plot(apartment_stock['year'], apartment_stock['stock'], ...)
plt.plot: 재고 데이터를 선 그래프로 표시.annotate: 각 데이터 포인트에 값 라벨 추가.매매가격 지수 추세
plt.subplot(2, 1, 2) plt.plot(price_index['year'], price_index['index'], ...)
plt.plot: 매매가격 지수 데이터를 선 그래프로 표시.3. 상관관계 분석
산점도
sns.regplot(x='Stock', y='Price_Index', data=merged_data, color='#2ecc71')
sns.regplot: 재고와 가격 간의 산점도를 그리고 회귀선을 추가.- 상관계수와 p-value를 텍스트로 그래프에 추가하여 상관관계의 유의성을 강조.
상관행렬 히트맵
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', ...)
sns.heatmap: 상관계수를 히트맵으로 시각화.
7. 인사이트 및 결론
추세 요약
- 아파트 재고와 매매가격 지수는 꾸준히 상승 추세를 보이다가 최근 하락.
- 재고 증가는 매매가격 지수 상승과 연관되어 있으며, 이는 부동산 시장의 주요 특징을 반영.
정책적 시사점
- 재고 공급 관리: 지속적인 공급 확대는 매매가격 안정화에 기여할 가능성이 큼.
- 금리 변화 대응: 금리 인상과 같은 외부 요인은 시장에 큰 영향을 미칠 수 있어 정책적 조율 필요.
파이썬 데이터 시각화를 활용한 이번 분석은 부동산 시장의 동향을 이해하고, 더 나은 정책 설계를 위한 기초 자료로 활용될 수 있습니다. 데이터를 기반으로 한 의사결정을 통해 부동산 시장의 안정성을 도모해야 합니다.
참고로, 에러바 그래프라고 들어보셨나요? 에러바 그래프와 에러바의 의미: 파이썬으로 데이터 신뢰도 시각화하기 포스트를 통해서 관련 내용을 확인해 보시고, 관련 지식을 업그레이드 해보세요!






