kavelaltd's picture
Upload folder using huggingface_hub
642a243 verified
Raw
History Blame Contribute Delete
1.65 kB
"""
HistorySaid Global Economic Dataset — Python Quick Start
Requires: pandas, matplotlib
"""
import pandas as pd
import matplotlib.pyplot as plt
# Load the unified dataset
df = pd.read_parquet("data/unified/all_indicators.parquet")
print(f"Dataset: {len(df):,} rows, {df['country_code'].nunique()} countries, {df['indicator_id'].nunique()} indicators")
print(f"Year range: {df['year'].min()}{df['year'].max()}")
print()
# --- Filter by country and indicator ---
usa_gdp = df[(df["country_code"] == "USA") & (df["indicator_id"] == "wb.NY.GDP.MKTP.CD")]
usa_gdp = usa_gdp.dropna(subset=["value"]).sort_values("year")
print("USA GDP (last 10 years):")
print(usa_gdp[["year", "value"]].tail(10).to_string(index=False))
print()
# --- Compare countries ---
countries = ["USA", "CHN", "DEU", "JPN", "IND"]
gdp = df[(df["indicator_id"] == "wb.NY.GDP.MKTP.CD") & (df["country_code"].isin(countries)) & (df["year"] == 2022)]
gdp = gdp.sort_values("value", ascending=False)
print("GDP comparison (2022):")
print(gdp[["country_name", "value"]].to_string(index=False))
print()
# --- Plot time series ---
fig, ax = plt.subplots(figsize=(10, 5))
for cc in countries:
sub = df[(df["country_code"] == cc) & (df["indicator_id"] == "wb.NY.GDP.MKTP.CD")]
sub = sub.dropna(subset=["value"]).sort_values("year")
ax.plot(sub["year"], sub["value"] / 1e12, label=sub["country_name"].iloc[0])
ax.set_title("GDP (trillions USD)")
ax.set_xlabel("Year")
ax.set_ylabel("Trillions USD")
ax.legend()
ax.grid(True)
plt.tight_layout()
plt.savefig("gdp_comparison.png", dpi=150)
print("Plot saved to gdp_comparison.png")