Real Estate Data Analysis Project in Python

Data Science project 17

Real Estate Data Analysis Project in Python

Build a complete real estate data analysis workflow with reproducible Python code, traceable calculations, validation checks, and honest limitations.

Explore Data Science training in VizagView all project ideas

Analysis question

How do median price, price per square foot, and area differ across the fictional localities?

Dataset

One thousand synthetic property records with fictional localities, area, bedroom count, age, and generated INR prices.

Requirements

  • Python 3.10 or later
  • A terminal or command prompt
  • python -m pip install numpy pandas
  • About 45-60 minutes to build and review

Method and data checks

Calculate price per square foot, aggregate robust locality medians and listing counts, and measure the overall linear association between area and generated price.

  • All property IDs are unique
  • Price per square foot uses positive area
  • Medians reduce the effect of extreme listings
  • Locality names and prices are explicitly fictional

Complete Python code

Save the program as ds_real_estate_analysis.py. The dataset generator or loader, analysis functions, output, and reproducibility controls are included.

"""Analyse synthetic property listings and price-per-area patterns."""

from __future__ import annotations

import numpy as np
import pandas as pd


def make_demo_properties(n: int = 1_000, seed: int = 42) -> pd.DataFrame:
    rng = np.random.default_rng(seed)
    locality = rng.choice(["Central", "Coastal", "North", "South"], n, p=[0.27, 0.23, 0.25, 0.25])
    area = np.clip(rng.normal(1250, 420, n), 450, 3000)
    bedrooms = np.clip(np.rint(area / 520 + rng.normal(0, 0.5, n)), 1, 5).astype(int)
    age = rng.integers(0, 31, n)
    locality_rate = pd.Series(locality).map({"Central": 7800, "Coastal": 9000, "North": 5800, "South": 6400}).to_numpy()
    price = area * locality_rate * (1 - 0.009 * age) + bedrooms * 180_000 + rng.normal(0, 600_000, n)
    return pd.DataFrame({"property_id": range(1, n + 1), "locality": locality, "area_sqft": area.round(), "bedrooms": bedrooms, "age_years": age, "price_inr": np.maximum(price, 1_000_000).round()})


def analyse_properties(data: pd.DataFrame) -> tuple[pd.DataFrame, dict[str, float]]:
    homes = data.copy()
    homes["price_per_sqft"] = homes["price_inr"] / homes["area_sqft"]
    locality = homes.groupby("locality", as_index=False).agg(listings=("property_id", "size"), median_price=("price_inr", "median"), median_price_per_sqft=("price_per_sqft", "median"), median_area=("area_sqft", "median")).sort_values("median_price_per_sqft", ascending=False)
    return locality, {"median_price": float(homes["price_inr"].median()), "area_price_correlation": float(homes[["area_sqft", "price_inr"]].corr().iloc[0, 1])}


def main() -> None:
    table, kpis = analyse_properties(make_demo_properties())
    print({k: round(v, 3) for k, v in kpis.items()})
    print(table.round(2).to_string(index=False))
    print("Synthetic teaching data — not a valuation, appraisal, or real locality comparison.")


if __name__ == "__main__":
    main()

Run the project

  1. Create and activate a virtual environment.
  2. Install dependencies with python -m pip install numpy pandas.
  3. Run python ds_real_estate_analysis.py.
  4. Reconcile row counts and totals before interpreting patterns.
  5. Read the limitations before substituting any real dataset.

Expected analytical output

Locality listing counts and medians plus overall median price and area-price correlation.

Interpretation and responsible-use limits

Synthetic education only. These results are not a valuation, appraisal, listing recommendation, legal opinion, lending input, or statement about any real locality.

Ways to extend the project

Use verified transactions, distinguish asking and sale price, add sale date and property type, remove duplicate listings, map uncertainty, and document geographic coverage.

Continue learning Data Science

Try the next project, return to the Softenant project library, or explore the Data Science course in Vizag for guided data cleaning, analysis, visualisation, and portfolio feedback.