Data Science project 20
World Happiness Report-Style Data Analysis Project
Build a complete world happiness report 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 can factor correlations and score-quartile profiles be explored without making claims about real countries or the official report?
Dataset
One hundred twenty fictional demo countries with generated income, social-support, healthy-life, freedom, generosity, and happiness-score values.
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
Select numeric variables, calculate correlations with the generated score, create equal-frequency score quartiles, compare quartile means, and display five highest synthetic scores.
- Entities are named Demo Country rather than real places
- Every value is generated by a fixed seed
- Quartiles are based on the synthetic score
- Correlation is not described as causal contribution
Complete Python code
Save the program as ds_world_happiness_analysis.py. The dataset generator or loader, analysis functions, output, and reproducibility controls are included.
"""Explore synthetic well-being indicators without making country claims."""
from __future__ import annotations
import numpy as np
import pandas as pd
def make_demo_happiness(n: int = 120, seed: int = 42) -> pd.DataFrame:
rng = np.random.default_rng(seed)
income = rng.uniform(0.15, 1.0, n)
social_support = rng.beta(5, 2, n)
healthy_life = rng.uniform(0.35, 0.95, n)
freedom = rng.beta(4, 2.5, n)
generosity = rng.beta(2, 5, n)
score = 2.1 + 1.35 * income + 1.2 * social_support + 1.0 * healthy_life + 0.8 * freedom + 0.25 * generosity + rng.normal(0, 0.28, n)
return pd.DataFrame({"entity": [f"Demo Country {i:03d}" for i in range(1, n + 1)], "income_index": income, "social_support": social_support, "healthy_life_index": healthy_life, "freedom_index": freedom, "generosity_index": generosity, "happiness_score": np.clip(score, 1, 10)})
def analyse_happiness(data: pd.DataFrame) -> dict[str, object]:
numeric = data.select_dtypes("number")
correlations = numeric.corr()["happiness_score"].drop("happiness_score").sort_values(ascending=False)
quartiles = data.assign(score_quartile=pd.qcut(data["happiness_score"], 4, labels=["Q1", "Q2", "Q3", "Q4"]))
comparison = quartiles.groupby("score_quartile", observed=True).mean(numeric_only=True).reset_index()
return {"correlations": correlations, "quartiles": comparison, "top_entities": data.nlargest(5, "happiness_score")[["entity", "happiness_score"]]}
def main() -> None:
result = analyse_happiness(make_demo_happiness())
print("Correlations with synthetic score:\n", result["correlations"].round(3).to_string())
print("\nQuartile comparison:\n", result["quartiles"].round(3).to_string(index=False))
print("Synthetic entities and scores — not the official World Happiness Report.")
if __name__ == "__main__":
main()
Run the project
- Create and activate a virtual environment.
- Install dependencies with
python -m pip install numpy pandas. - Run
python ds_world_happiness_analysis.py. - Reconcile row counts and totals before interpreting patterns.
- Read the limitations before substituting any real dataset.
Expected analytical output
A ranked correlation series, quartile comparison table, and five synthetic top entities.
Interpretation and responsible-use limits
This project is not the official World Happiness Report and contains no real country results. Real analysis must cite the report edition, survey methodology, uncertainty, coverage, and variable definitions.
Ways to extend the project
Use a licensed official edition, retain confidence intervals, compare years carefully, visualise regional distributions, test rank uncertainty, and avoid causal claims from correlations.
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.