公寓销售价格指数与公寓库存数量的关联:用 Python 展示数据
在房地产市场中,公寓库存数量和公寓销售价格指数是了解市场状况的关键指标。分析这两个指标之间的关系不仅可以揭示供求关系的相互作用,还可以揭示经济因素。
在本篇文章中,我们将向您展示如何使用 Python 将 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 年的约 548 万到 2022 年的约 1227 万,大约翻了一番。
- 库存增长加快,尤其是自 2010 年以来。
公寓销售价格指数趋势分析(2014-2023 年)

- 该指数从 2014 年的 80.9 升至 2022 年的峰值(106)后,于 2023 年降至 92.7。
- 由于利率上升和经济放缓,这一数字很可能会下降。
4. 关联分析
相关散点图

- 相关系数 0.82这表明公寓库存与销售价格指数之间存在很强的正相关性。
- p 值为 0.0136,具有统计学意义,表明这两个变量之间的关系并非偶然。
相关矩阵热图

- 这两个变量之间的相关系数(0.82)在热图中清晰可见。
5. 完整的 Python 代码
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy import stats
创建 # 数据
apartment_stock = pd.DataFrame({
年份[2000, 2005, 2010, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022],
股票':[5479828, 6962689, 8576013, 9806062, 10029644, 10375363, 10826044, 11287048, 11661851, 11948544, 12268973]
})
price_index = pd.DataFrame({
年份':[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]
})
# 创建带子图的图形
plt.figure(figsize=(12, 12))
# 1.公寓股票走势
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('单位数量',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)
# 添加数值标签
for x, y in zip(apartment_stock['year'], apartment_stock['stock']):
plt.annotate(f'{y:,.0f}'、
(x, y)、
textcoords="偏移点"、
xytext=(0,10)、
ha='center'、
fontsize=8)
# 2.价格指数趋势
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('价格指数(2021.6=100)', fontsize=12)
plt.grid(True, linestyle='--', alpha=0.7)
plt.xticks(rotation=45)
# 添加数值标签
for x, y in zip(price_index['year'], price_index['index']):
plt.annotate(f'{y:.1f}'、
(x, y)、
textcoords="偏移点"、
xytext=(0,10)、
ha='center'、
fontsize=8)
plt.tight_layout()
plt.show()
# 相关性分析
# 合并重叠年份的数据集
merged_data = pd.merge(apartment_stock, price_index, on='year', how='inner')
merged_data.columns = ['Year', 'Stock', 'Price_Index'] (合并数据的列数)
# 创建相关性可视化
plt.figure(figsize=(15, 5))
# 1.带回归线的散点图
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('价格指数',fontsize=12)
plt.gca().xaxis.set_major_formatter(plt.FuncFormatter(lambda x, p: format(int(x/1000000), ',') + 'M'))
# 计算相关系数和 p 值
correlation_coefficient, p_value = stats.pearsonr(merged_data['Stock'], merged_data['Price_Index'])
# 为图表添加相关信息
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. 相关矩阵热图
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({...})
公寓库存:生成 2000 年至 2022 年的公寓存量数据。价格指数:生成 2014 年至 2023 年的销售价格指数数据。2. 视觉化
公寓库存趋势
plt.subplot(2, 1, 1) plt.plot(apartment_stock['year'], apartment_stock['stock'], ...)
plt.plot:以折线图的形式显示库存数据。诠释为每个数据点添加数值标签。交易价格指数趋势
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 值作为文本添加到图表中,以突出相关性的重要性。
相关矩阵热图
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', ...)
sns.heatmap相关系数:以热图形式显示相关系数。
7 见解和结论
趋势摘要
- 公寓库存和销售价格指数一直呈稳步上升趋势,但最近有所下降。
- 库存的增加与销售价格指数的上升相关联,反映了房地产市场的一个主要特征。
政策影响
- 管理库存供应价格稳定:继续扩大供应可能有助于价格稳定。
- 应对利率变化利率上调等外部因素会对市场产生重大影响,需要进行政策协调。
利用 Python 数据可视化技术进行的分析可用于了解房地产市场的发展趋势,并为更好地制定政策提供依据。应做出以数据为导向的决策,以促进房地产市场的稳定。
对了,你听说过误差柱形图吗? 误差条图及其含义:用 Python 可视化数据置信度 查看该文章,了解更多相关信息,提升您的知识水平!






