一键导入
dst-data
Fetch actual data from Danmarks Statistik API and store in DuckDB. Use when user wants to download and store specific DST table data for analysis.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Fetch actual data from Danmarks Statistik API and store in DuckDB. Use when user wants to download and store specific DST table data for analysis.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Documentation of available data science libraries (scipy, numpy, pandas, sklearn) and best practices for statistical analysis, regression modeling, and organizing analysis scripts. **CRITICAL:** All analysis scripts MUST be placed in reports/{topic}/scripts/, NOT in root scripts/ directory.
Check data freshness and age for DST tables in DuckDB. Use when determining if data needs refreshing or validating data currency before analysis.
Perform SQL joins and multi-table analysis on DST data in DuckDB. Use when research requires combining multiple tables on common dimensions (time, region). Provides patterns for common DST dimension joins and multi-table comparisons.
List all Danmarks Statistik tables currently stored in DuckDB with metadata. Use when user wants to know what data is available locally or explore stored tables.
Execute SQL queries on Danmarks Statistik data stored in DuckDB. Use when user needs specific data analysis, filtering, aggregation, or joins. Also includes table summary functionality.
Generate HTML research reports with embedded data, charts, and analysis. Use when creating final research deliverables. Supports single comprehensive reports or multiple focused reports. Handles styling, structure, and output to reports/ directory.
| name | dst-data |
| description | Fetch actual data from Danmarks Statistik API and store in DuckDB. Use when user wants to download and store specific DST table data for analysis. |
Fetch statistical data from Danmarks Statistik API and persist it in the local DuckDB database for analysis. This is the final step in the data acquisition workflow, transforming remote API data into queryable local tables.
DST's BULK format (unlimited streaming) has a critical requirement:
ALL variables must be specified in filters - no auto-elimination like other formats.
Error: "Der skal vælges værdier for variabel: [VAR_NAME]"
Solution:
{"VAR1":["*"], "VAR2":["*"], ...}"*" to get all values for a variableDST uses ".." to indicate suppressed/confidential data.
Impact:
CAST('..' AS INTEGER) failsSolutions:
WHERE column != '..'CASE WHEN column != '..' THEN CAST(column AS INTEGER) ENDsafe_numeric_cast(column) from scripts/db/helpers.pyError: "Forespørgslen returnerer for mange observationer" (REQUEST-LIMIT)
Solution: Use BULK format automatically (done by fetch_and_store.py)
Message: "Der skal vælges værdier for variabel: X" Cause: BULK format missing variable in filters Fix: Add variable to filters with at least one value
Messages:
Fix: Verify IDs against tableinfo output
Message: "Forespørgslen returnerer for mange observationer" Cause: Request exceeds 1M cells (non-BULK formats) Fix: Use BULK format or add more filters
The fetch_and_store.py script combines fetching and storing in one command. This is the recommended approach.
Fetch and store a complete table:
python scripts/fetch_and_store.py --table-id <TABLE_ID>
Fetch only specific data using filters:
python scripts/fetch_and_store.py --table-id <TABLE_ID> --filters '<JSON>'
Example filters:
# Filter by region
--filters '{"OMRÅDE":["000"]}'
# Filter by time period
--filters '{"TID":["2024*"]}'
# Multiple filters
--filters '{"OMRÅDE":["000","101"],"TID":["2024*"]}'
Replace existing table:
python scripts/fetch_and_store.py --table-id <TABLE_ID> --overwrite
Only fetch if data is older than threshold:
python scripts/fetch_and_store.py --table-id <TABLE_ID> --skip-if-fresh --max-age-days 30
For advanced users who need more control, fetch and store can be done separately.
Download data from API:
python scripts/api/fetch_data.py --table-id <TABLE_ID> --output data.json
Save to DuckDB:
python scripts/db/store_data.py --table-id <TABLE_ID> --data-file data.json
dst_{table_id} (lowercase)dst_folk1adst_metadata table✓ Created table dst_folk1a with 45231 records
⊘ Skipped FOLK1A: data_is_fresh
Exit codes:
;) not comma--overwrite to replace existing data* (all), prefix*, *suffix, >=value, <=value(1) (latest), (-n+5) (last 5), 2024* (year match)After storing data, verify success:
python scripts/db/query_metadata.py --table-id <TABLE_ID>
python scripts/db/query_data.py --sql "SELECT * FROM dst_<table_id> LIMIT 5"
Compare record count in metadata with table info expectations.
After successfully storing data:
Example:
python scripts/db/table_summary.py --table-id FOLK1A
python scripts/fetch_and_store.py --table-id FOLK1A
python scripts/fetch_and_store.py --table-id FOLK1A --overwrite
python scripts/fetch_and_store.py --table-id FOLK1A --filters '{"OMRÅDE":["000","101"]}'
python scripts/fetch_and_store.py --table-id FOLK1A --skip-if-fresh --max-age-days 7
# Step 1: Fetch
python scripts/api/fetch_data.py --table-id FOLK1A --output folk1a.json
# Step 2: Store
python scripts/db/store_data.py --table-id FOLK1A --data-file folk1a.json
python scripts/api/fetch_data.py --table-id FOLK1A --format csv --output data.csv
# Latest period (recommended for current data)
--filters '{"Tid":["(1)"]}'
# Last 5 periods
--filters '{"Tid":["(-n+5)"]}'
# Specific year
--filters '{"Tid":["2024"]}'
# Year range (wildcard)
--filters '{"Tid":["202*"]}'
# Specific quarters (K=Kvartal)
--filters '{"Tid":["2024K1","2024K2"]}'
# All Q1 quarters
--filters '{"Tid":["*K1"]}'
# Range operator
--filters '{"Tid":[">=2023K1<=2024K4"]}'
# Whole country
--filters '{"OMRÅDE":["000"]}'
# Specific regions
--filters '{"OMRÅDE":["101","147"]}'
# All regions (wildcard)
--filters '{"OMRÅDE":["*"]}'
# Region codes: 000=Denmark, 101=Copenhagen, 147=Frederiksberg
# Multiple dimensions with patterns
--filters '{"OMRÅDE":["000"],"Tid":["(1)"],"KØN":["*"]}'
# Complex filtering
--filters '{"OMRÅDE":["101","147"],"Tid":[">=2020"],"KØN":["1","2"]}'
* - All valuesprefix* - Starts with prefix*suffix - Ends with suffix(1) - Latest period (nth-rule)(-n+N) - Last N periods>=value - From value onwards<=value - Up to value>=A<=B - Between A and B--overwrite flag to replace existing dataError message: "Forespørgslen returnerer for mange observationer"
Error message: "Der skal vælges værdier for variabel: [VARIABLE_NAME]"
Error messages: "Tabellen blev ikke fundet" / "Variablen blev ikke fundet" / "Værdien blev ikke fundet"
*, ranges need >=/<=Error message: "Der kan ikke vælges sortering af tid for streamede formater"