Upload folder using huggingface_hub
Browse files- README.md +3 -10
- datapackage.yaml +2 -2
- wdi.py +100 -0
README.md
CHANGED
|
@@ -1,16 +1,9 @@
|
|
| 1 |
-
|
| 2 |
---
|
| 3 |
license: mit
|
| 4 |
---
|
| 5 |
-
# world_development_indicators
|
| 6 |
-
|
| 7 |
-
World Development Indicators (WDI) is the World Bank's premier compilation of cross-country comparable data on development.
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
a fully open-source, serverless, and local-first Data Platform that improves how communities collaborate on Open Data.
|
| 13 |
|
| 14 |
-
|
| 15 |
-
- **Number of rows:** 8883048
|
| 16 |
-
- **Number of columns:** 6
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# World Development Indicators
|
| 6 |
|
| 7 |
+
World Development Indicators (WDI) is the World Bank's premier compilation of cross-country comparable data on development.
|
|
|
|
| 8 |
|
| 9 |
+
This dataset is produced and published automatically by [Datadex](https://github.com/davidgasquez/datadex), a fully open-source, serverless, and local-first Data Platform that improves how communities collaborate on Open Data.
|
|
|
|
|
|
datapackage.yaml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
name: world_development_indicators
|
| 2 |
resources:
|
| 3 |
-
- format: parquet
|
| 4 |
-
|
|
|
|
| 1 |
name: world_development_indicators
|
| 2 |
resources:
|
| 3 |
+
- format: parquet
|
| 4 |
+
path: data/world_development_indicators.parquet
|
wdi.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import warnings
|
| 3 |
+
import zipfile
|
| 4 |
+
|
| 5 |
+
import httpx
|
| 6 |
+
import polars as pl
|
| 7 |
+
|
| 8 |
+
from datadex import materialize
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def fetch_bytes(
|
| 12 |
+
url: str,
|
| 13 |
+
*,
|
| 14 |
+
timeout: float | httpx.Timeout = 120.0,
|
| 15 |
+
follow_redirects: bool = True,
|
| 16 |
+
) -> bytes:
|
| 17 |
+
"""Download the content at ``url`` and return the raw bytes.
|
| 18 |
+
|
| 19 |
+
The request is attempted with standard TLS verification. If that fails due to
|
| 20 |
+
certificate validation errors (common behind corporate proxies), a single
|
| 21 |
+
retry is performed with verification disabled while emitting a warning.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
headers = {"User-Agent": "datadex/0.1"}
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
response = httpx.get(
|
| 28 |
+
url,
|
| 29 |
+
follow_redirects=follow_redirects,
|
| 30 |
+
timeout=timeout,
|
| 31 |
+
headers=headers,
|
| 32 |
+
)
|
| 33 |
+
except httpx.HTTPError as exc:
|
| 34 |
+
if "CERTIFICATE_VERIFY_FAILED" not in repr(exc):
|
| 35 |
+
raise
|
| 36 |
+
|
| 37 |
+
warnings.warn(
|
| 38 |
+
f"Falling back to insecure TLS download for {url}",
|
| 39 |
+
RuntimeWarning,
|
| 40 |
+
stacklevel=2,
|
| 41 |
+
)
|
| 42 |
+
else:
|
| 43 |
+
response.raise_for_status()
|
| 44 |
+
return response.content
|
| 45 |
+
|
| 46 |
+
response = httpx.get(
|
| 47 |
+
url,
|
| 48 |
+
follow_redirects=follow_redirects,
|
| 49 |
+
timeout=timeout,
|
| 50 |
+
headers=headers,
|
| 51 |
+
verify=False,
|
| 52 |
+
)
|
| 53 |
+
response.raise_for_status()
|
| 54 |
+
return response.content
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def world_development_indicators() -> pl.DataFrame:
|
| 58 |
+
"""
|
| 59 |
+
World Development Indicators (WDI) is the World Bank's premier compilation of cross-country comparable data on development.
|
| 60 |
+
|
| 61 |
+
Bulk data download is available at https://datatopics.worldbank.org/world-development-indicators/
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
+
url = "https://databank.worldbank.org/data/download/WDI_CSV.zip"
|
| 65 |
+
|
| 66 |
+
archive_bytes = fetch_bytes(url, timeout=300.0)
|
| 67 |
+
|
| 68 |
+
with zipfile.ZipFile(io.BytesIO(archive_bytes)) as archive:
|
| 69 |
+
with archive.open("WDICSV.csv") as csv_file:
|
| 70 |
+
df = pl.read_csv(csv_file)
|
| 71 |
+
|
| 72 |
+
# Reshape the dataframe
|
| 73 |
+
df = df.unpivot(
|
| 74 |
+
index=["Country Name", "Country Code", "Indicator Name", "Indicator Code"],
|
| 75 |
+
value_name="Indicator Value",
|
| 76 |
+
variable_name="Year",
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
df = df.with_columns(pl.col("Year").cast(pl.Int32))
|
| 80 |
+
|
| 81 |
+
df = df.rename({
|
| 82 |
+
"Country Name": "country_name",
|
| 83 |
+
"Country Code": "country_code",
|
| 84 |
+
"Indicator Name": "indicator_name",
|
| 85 |
+
"Indicator Code": "indicator_code",
|
| 86 |
+
"Year": "year",
|
| 87 |
+
"Indicator Value": "indicator_value",
|
| 88 |
+
})
|
| 89 |
+
|
| 90 |
+
df = df.drop_nulls(subset=["indicator_value"])
|
| 91 |
+
|
| 92 |
+
return df.sort(["country_code", "year", "indicator_code"])
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def main() -> None:
|
| 96 |
+
materialize(world_development_indicators)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
main()
|