Code Speaks: Reading Japan’s Public Data as Infrastructure

IT Policy Proposals
Code Speaks: Reading Japan’s Public Data as Infrastructure

どうも〜おかむーです!今日はちょっとエンジニアっぽい話をしますよ〜

  • Government publishes a lot of CSVs, but machine-readability and schema quality vary widely
  • Key issues: encoding, missing metadata, inconsistent codes; fixable with API+schema work
  • Practical recipe: fetch CSVs, normalize codes (use soumu mapping), validate, expose as versioned JSON/CSV

結論

Public data exists in many places (notice.go.jp, env.go.jp, mhlw.go.jp, soumu.go.jp...), but the current landscape is a mixture of usable CSVs and frustrating edge cases. As an engineer, I think the priority is: canonical code tables + consistent encodings + per-file schema (CSVW/JSON-LD) + a lightweight API gateway. 要するに、データを“プログラムが使える形”に揃えれば、政策評価も自動化できるってことです。

Report: what I looked at and what it implies

What’s available (examples)

  • NOTICE: https://notice.go.jp/docs/status_notice.csv — a direct CSV, nice!
  • env.go.jp CSV (prefecture dataset) — CSV is good but need schema
  • inpit.go.jp domestic migration CSV — legacy tables often lack metadata
  • mhlw.go.jp CSVs — frequent encoding quirks and inconsistent column names
  • soumu.go.jp code mapping: https://www.soumu.go.jp/main_content/000420038.csv — critical for joins

Check this out: many agencies already publish CSVs, which is excellent. But CSV alone isn’t enough if encoding, column semantics, and stable identifiers are missing.

Technical problems I repeatedly see

  • Encoding ambiguity (Shift_JIS vs UTF-8 vs BOM). Code readers choke unless you detect encoding.
  • Missing machine-readable metadata (what do columns mean? units? fiscal year?). Without that you can’t compute KPI gaps reliably.
  • Inconsistent identifier types: sometimes numeric codes are zero-padded, sometimes not — joins fail.
  • No centralized API or consistent versioning: pulling many CSVs for reproducible analysis is painful.

Practical engineering checks (how I’d validate)

  • Verify encoding and normalize to UTF-8.
  • Coerce identifier columns to string and normalize padding.
  • Use soumu code mapping as canonical join key for administrative areas.
  • Validate time-series continuity and KPI fields.

Example Python snippet (pseudocode you can run):

import requests, chardet, pandas as pd

r = requests.get('https://notice.go.jp/docs/status_notice.csv')

enc = chardet.detect(r.content)['encoding']

df = pd.read_csv(io.BytesIO(r.content), encoding=enc, dtype=str)

normalize codes

df['pref_code'] = df['pref_code'].str.zfill(2)

join with Soumu mapping

codes = pd.read_csv('https://www.soumu.go.jp/main_content/000420038.csv', dtype=str)

merged = df.merge(codes, left_on='pref_code', right_on='code', how='left')

要するに、encoding detection + dtype=str + canonical code joinがセットです。

Policy evaluation: KPI vs actuals

Most policy documents provide targets, but CSVs rarely include clearly labeled target vs actual fields or timestamps in ISO format. That makes computing the gap a multi-step ETL job: extract (CSV), normalize (codes/dates/units), transform (compute rate/percentage), load (analytics DB). If agencies published a small machine-readable KPI manifest per program (JSON with target, baseline, unit, time_horizon), automated monitoring becomes trivial.

Design proposals (engineering-first)

  • Publish a per-file CSVW/JSON-LD schema alongside each CSV (column types, units, licenses). That’s low-effort and huge ROI.
  • Canonical code service: a single API endpoint that returns administrative code mappings (versioned). Use soumu as source of truth.
  • Minimal REST API: /datasets/{id}/{version}/rows.json with pagination + CSV download, plus ETag and timestamps.
  • Adopt UTF-8 with BOM-free files, or always indicate encoding in HTTP headers.
  • Offer a small SDK (Python) that wraps fetching, encoding normalization, and joins to the canonical codes.

Quick architecture sketch

  • Ingest layer: periodic fetch of agency CSVs (with encoding detection)
  • Normalizer: apply CSVW schemas, coerce columns, pad codes, validate types
  • Storage: columnar store (Parquet) + analytics DB for KPI queries
  • API: versioned, supports JSON/CSV, has dataset-level metadata (DCAT, license)

まとめ

現状、政府のCSV公開はあるけど“エンジニアがすぐ使える状態”には差がある。解決は単純で、スキーマ宣言(CSVW/JSON-LD)、コードの正規化(soumuのマッピング活用)、エンコーディング統一、そして小さいAPIゲートウェイを作ること。これだけで政策のモニタリングや再現可能な分析が一気に捗りますよね。

おかむーから一言

テクノロジーは細かいところを揃えるだけで社会を変えます。投資は小さく、リターンは大きい。やりましょう!