Correlating Apartment Sales Price Index with Apartment Inventory Count: Visualizing Data with Python
In the real estate market, the number of apartment inventories and the apartment sales price index are key indicators for understanding market conditions. Analyzing the relationship between the two indicators can reveal not only the interaction of supply and demand, but also economic factors.
In this post, we'll show you how to use Python to visualize apartment inventory and sales price index data from 2000 to 2023 and analyze the correlation between the two variables. The analysis and graphs will reveal key trends and insights in the real estate market.
1. Data overview and definitions
Number of apartment inventory
- Represents the number of apartments built for one household to live in.
- Requirements: Permanent building, at least one room and kitchen, independent entrance, and an apartment that is customarily owned or sold as a unit.
- Source: Statistics Korea, "General Housing Survey"
Apartment Sales Price Index
- A price index that sets the home sale price at the baseline (June 2021) to 100.
- Interpretation
- If the index is higher than 100, the price has increased from the baseline.
- If the index is lower than 100, the price is down from the reference point.
- Source: Korea Institute of Statistics, "National House Price Trend Survey"
2. data table
Number of apartments in stock (2000-2022)
| Year | ’00 | ’05 | ’10 | ’15 | ’16 | ’17 | ’18 | ’19 | ’20 | ’21 | ’22 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Number of inventory (issues) | 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 |
Apartment Sales Price Index (2014-2023)
| 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 |
3. visualization and analytics
Trend analysis of apartment inventory numbers (2000-2022)

- Roughly doubling from about 5.48M in 2000 to about 12.27M in 2022.
- Inventory growth has accelerated, especially since 2010.
Apartment Sales Price Index Trend Analysis (2014-2023)

- After reaching a peak (106) in 2022 from 80.9 in 2014, the index fell to 92.7 in 2023.
- It is likely to fall due to rising interest rates and a slowing economy.
4. Correlation analysis
Correlation scatterplot

- Correlation coefficient 0.82which shows a strong positive correlation between apartment inventory and the sales price index.
- The p-value is statistically significant at 0.0136, suggesting that the relationship between the two variables is not coincidental.
Correlation Matrix Heatmap

- The correlation coefficient (0.82) between the two variables is clearly visible in the heatmap.
5. full Python code
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. detailed code commentary
1. generate data
apartment_stock = pd.DataFrame({...}) price_index = pd.DataFrame({...})
apartment_stock: Generate apartment inventory data from 2000 to 2022.price_index: Generate sales price index data from 2014 to 2023.2. visualize
Apartment inventory trends
plt.subplot(2, 1, 1) plt.plot(apartment_stock['year'], apartment_stock['stock'], ...)
plt.plot: Display inventory data as a line graph.annotate: Add a value label to each data point.Trading Price Index Trends
plt.subplot(2, 1, 2) plt.plot(price_index['year'], price_index['index'], ...)
plt.plot: Plotting the price index data as a line graph.3. Correlation analysis
Scatter Plots
sns.regplot(x='Stock', y='Price_Index', data=merged_data, color='#2ecc71')
sns.regplot: Draw a scatter plot between inventory and price and add a regression line.- Add the correlation coefficient and p-value to the graph as text to emphasize the significance of the correlation.
Correlation Matrix Heatmap
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', ...)
sns.heatmap: Visualize the correlation coefficient as a heatmap.
7. Insights and conclusions
Trend summary
- Apartment inventory and sales price indices have been trending steadily upward before recently declining.
- Inventory growth is associated with an increase in the sales price index, reflecting a key feature of the real estate market.
Policy implications
- Manage inventory supply: Continued supply expansion is likely to contribute to price stabilization.
- Responding to interest rate changesExternal factors such as interest rate hikes can have a significant impact on the market, requiring policy coordination.
This analysis using Python data visualization can be used to understand trends in the real estate market and serve as a basis for better policy design. We need to make data-driven decisions to stabilize the real estate market.
By the way, have you heard of an error bar graph? Errorbar Graphs and What They Mean: Visualizing Data Confidence in Python Check out this post to learn more about it, and upgrade your knowledge!






