diff --git a/.cursor/rules/dataframe-serialization.mdc b/.cursor/rules/dataframe-serialization.mdc
new file mode 100644
index 00000000..47d1ab5a
--- /dev/null
+++ b/.cursor/rules/dataframe-serialization.mdc
@@ -0,0 +1,48 @@
+# DataFrame Serialization
+
+All DataFrame-to-records conversion for API responses, streaming events, or
+frontend-visible data MUST use the centralized helpers in
+`data_formulator.datalake.parquet_utils`:
+
+| Source type | Helper |
+|---|---|
+| `pd.DataFrame` | `df_to_safe_records(df)` |
+| `pa.Table` (Arrow) | `get_sample_rows_from_arrow(table)` |
+
+## Why
+
+`pandas.DataFrame.to_json(orient='records')` defaults to `date_format='epoch'`,
+which serializes datetime columns as **epoch milliseconds** (e.g. `1773532800000`).
+The frontend interprets these as plain numbers and renders them with commas
+(`1,773,532,800,000`) instead of formatted dates.
+
+`df_to_safe_records` enforces `date_format='iso'` and `default_handler=str`,
+ensuring datetimes become ISO-8601 strings and exotic types degrade gracefully.
+
+## Banned Patterns
+
+```python
+# BAD — missing date_format, datetimes become epoch numbers
+json.loads(df.to_json(orient='records'))
+
+# BAD — to_dict returns Timestamp objects, not JSON-safe values
+df.to_dict(orient='records')
+
+# ACCEPTABLE but should be unified for consistency
+json.loads(df.to_json(orient='records', date_format='iso'))
+```
+
+## Correct Pattern
+
+```python
+from data_formulator.datalake.parquet_utils import df_to_safe_records
+
+rows = df_to_safe_records(df)
+preview = df_to_safe_records(df.head(5))
+```
+
+## Exceptions
+
+Internal data processing that never reaches the frontend or JSON serialization
+(e.g. Kusto SDK metadata parsing, Vega-Lite spec construction) may use
+`to_dict(orient='records')` directly.
diff --git a/.cursor/rules/dev-guides-first.mdc b/.cursor/rules/dev-guides-first.mdc
index 118ea366..73695347 100644
--- a/.cursor/rules/dev-guides-first.mdc
+++ b/.cursor/rules/dev-guides-first.mdc
@@ -9,21 +9,23 @@ alwaysApply: true
## Before Starting Any Development
Before implementing or designing a new feature, module, or significant change, **always
-read the relevant documents in `dev-guides/`** to understand existing conventions:
+read the relevant documents in `docs/dev-guides/`** to understand existing conventions:
| Guide | When to Read |
|-------|-------------|
-| `dev-guides/1-streaming-protocol.md` | Any work on streaming endpoints or NDJSON protocol |
-| `dev-guides/2-log-sanitization.md` | Any work involving logging, credentials, external services, or DataLoaders |
-| `dev-guides/3-data-loader-development.md` | Any work on ExternalDataLoader, DataConnector, or connector routes |
-| `dev-guides/4-authentication-oidc-tokenstore.md` | Any work on OIDC, TokenStore, AUTH_MODE, or SSO flows |
-| `dev-guides/6-i18n-language-injection.md` | Any work on Agent prompts, Agent routes, backend user-visible messages, or frontend i18n |
-| `dev-guides/7-unified-error-handling.md` | Any work on API errors, frontend API calls, streaming error events, or error tests |
-| `dev-guides/8-path-safety.md` | Any work on backend file access, downloads, Workspace paths, Agent tools, DataLoaders, or sandbox config |
-| `dev-guides/10-agent-knowledge-reasoning-log.md` | Any work on Agent knowledge injection, KnowledgeStore, reasoning logs, or experience distillation |
-| `dev-guides/11-catalog-metadata-sync.md` | Any work on catalog sync, catalog_cache, catalog_annotations, metadata merge, Agent catalog tools, or frontend catalog browsing |
-| `dev-guides/12-sandbox-session.md` | Any work on sandbox execution, Agent tool-calling loops, explore/execute_python code execution, or namespace management |
-| `dev-guides/13-unified-row-limits.md` | Any work on row limits, data loading size caps, frontendRowLimit, MAX_IMPORT_ROWS, or DataLoader size parameter |
+| `docs/dev-guides/1-streaming-protocol.md` | Any work on streaming endpoints or NDJSON protocol |
+| `docs/dev-guides/2-log-sanitization.md` | Any work involving logging, credentials, external services, or DataLoaders |
+| `docs/dev-guides/3-data-loader-development.md` | Any work on ExternalDataLoader, DataConnector, or connector routes |
+| `docs/dev-guides/4-authentication-oidc-tokenstore.md` | Any work on OIDC, TokenStore, AUTH_MODE, or SSO flows |
+| `docs/dev-guides/6-i18n-language-injection.md` | Any work on Agent prompts, Agent routes, backend user-visible messages, or frontend i18n |
+| `docs/dev-guides/7-unified-error-handling.md` | Any work on API errors, frontend API calls, streaming error events, or error tests |
+| `docs/dev-guides/8-path-safety.md` | Any work on backend file access, downloads, Workspace paths, Agent tools, DataLoaders, or sandbox config |
+| `docs/dev-guides/10-agent-knowledge-reasoning-log.md` | Any work on Agent knowledge injection, KnowledgeStore, reasoning logs, or experience distillation |
+| `docs/dev-guides/11-catalog-metadata-sync.md` | Any work on catalog sync, catalog_cache, catalog_annotations, metadata merge, Agent catalog tools, or frontend catalog browsing |
+| `docs/dev-guides/12-sandbox-session.md` | Any work on sandbox execution, Agent tool-calling loops, explore/execute_python code execution, or namespace management |
+| `docs/dev-guides/13-unified-row-limits.md` | Any work on row limits, data loading size caps, frontendRowLimit, MAX_IMPORT_ROWS, or DataLoader size parameter |
+| `docs/dev-guides/14-model-capability-runtime-degradation.md` | Any work on LLM Client calls, Agent LLM invocations, model capability checks, reasoning_effort, or image/vision degradation |
+| `docs/dev-guides/15-dataframe-serialization.md` | Any work on DataFrame→JSON serialization, Agent result rows, DataLoader sample_rows, or table API responses |
| `.cursor/rules/i18n-no-hardcoded-strings.mdc` | Any work adding or changing user-visible strings in `src/` |
Also check `.cursor/rules/` and `.cursor/skills/` for related coding conventions.
@@ -37,7 +39,7 @@ decision, you MUST update documentation before considering the task complete:
(e.g. new sensitive key type → update `2-log-sanitization.md`)
2. **Create new dev-guide** — if your change introduces a new cross-cutting convention
- that future developers must follow. Place in `dev-guides/` with the next number prefix.
+ that future developers must follow. Place in `docs/dev-guides/` with the next number prefix.
3. **Update existing SKILL** — if your change affects how an existing skill works
(e.g. new error handling pattern → update `error-handling/SKILL.md`)
@@ -55,7 +57,7 @@ decision, you MUST update documentation before considering the task complete:
For every PR that introduces new patterns:
-- [ ] Searched `dev-guides/` for related existing docs
+- [ ] Searched `docs/dev-guides/` for related existing docs
- [ ] Updated or created dev-guide if introducing cross-cutting conventions
- [ ] Updated or created `.cursor/skills/` if introducing reusable workflows
- [ ] Updated or created `.cursor/rules/` if introducing file-scoped constraints
diff --git a/.cursor/rules/error-response-safety.mdc b/.cursor/rules/error-response-safety.mdc
index 963f7394..76cbc7c7 100644
--- a/.cursor/rules/error-response-safety.mdc
+++ b/.cursor/rules/error-response-safety.mdc
@@ -10,7 +10,7 @@ Never return raw exception text (`str(e)`, `f"...{e}"`) directly in HTTP respons
Python exceptions may contain stack traces, file paths, database connection strings,
API keys, or internal IP addresses — all of which are security risks (CWE-209).
-See `dev-guides/7-unified-error-handling.md` for the full error handling contract.
+See `docs/dev-guides/7-unified-error-handling.md` for the full error handling contract.
## Unified Error System
diff --git a/.cursor/rules/language-injection-conventions.mdc b/.cursor/rules/language-injection-conventions.mdc
index 57c533e6..9ee458da 100644
--- a/.cursor/rules/language-injection-conventions.mdc
+++ b/.cursor/rules/language-injection-conventions.mdc
@@ -40,4 +40,4 @@ yield {
yield {"message": translate_in_python("empty_df", lang)}
```
-For detailed architecture and anti-pattern explanations, see `dev-guides/6-i18n-language-injection.md`.
+For detailed architecture and anti-pattern explanations, see `docs/dev-guides/6-i18n-language-injection.md`.
diff --git a/.cursor/rules/path-safety.mdc b/.cursor/rules/path-safety.mdc
index f53337d6..56de8eaf 100644
--- a/.cursor/rules/path-safety.mdc
+++ b/.cursor/rules/path-safety.mdc
@@ -6,7 +6,7 @@ alwaysApply: false
# 路径安全编码规范
-编辑此目录下的文件时,请遵守以下安全规则(详见 `dev-guides/8-path-safety.md` 和 `.cursor/skills/path-safety/SKILL.md`):
+编辑此目录下的文件时,请遵守以下安全规则(详见 `docs/dev-guides/8-path-safety.md` 和 `.cursor/skills/path-safety/SKILL.md`):
## ConfinedDir 是唯一的路径约束原语
diff --git a/.cursor/rules/unified-error-protocol.mdc b/.cursor/rules/unified-error-protocol.mdc
index 2e8eb3db..1428adee 100644
--- a/.cursor/rules/unified-error-protocol.mdc
+++ b/.cursor/rules/unified-error-protocol.mdc
@@ -6,7 +6,7 @@ alwaysApply: false
# Unified Error Protocol
-See `dev-guides/7-unified-error-handling.md` for the full developer guide.
+See `docs/dev-guides/7-unified-error-handling.md` for the full developer guide.
## HTTP Status Code Policy
diff --git a/.cursor/skills/error-handling/SKILL.md b/.cursor/skills/error-handling/SKILL.md
index 133992e2..bd09d21c 100644
--- a/.cursor/skills/error-handling/SKILL.md
+++ b/.cursor/skills/error-handling/SKILL.md
@@ -7,8 +7,8 @@ description: 统一错误处理系统。在添加 API 端点、修改错误处
Unified error handling system for DF. Use when adding API endpoints, modifying error handling, or adding frontend API calls.
-> **Prerequisites**: Read `dev-guides/7-unified-error-handling.md` before changing API error behavior.
-> Read `dev-guides/2-log-sanitization.md` when the work involves logging, credentials, external services, or DataLoaders.
+> **Prerequisites**: Read `docs/dev-guides/7-unified-error-handling.md` before changing API error behavior.
+> Read `docs/dev-guides/2-log-sanitization.md` when the work involves logging, credentials, external services, or DataLoaders.
> If your work introduces new error handling patterns or conventions, update this file and related dev-guides accordingly.
## Architecture Overview
diff --git a/.cursor/skills/language-injection/SKILL.md b/.cursor/skills/language-injection/SKILL.md
index a75c3a01..121bda64 100644
--- a/.cursor/skills/language-injection/SKILL.md
+++ b/.cursor/skills/language-injection/SKILL.md
@@ -5,9 +5,9 @@ description: LLM Agent 多语言注入规范。在修改 Agent 提示词、添
# Language Injection for Agent Prompts
-Authoritative developer guide: `dev-guides/6-i18n-language-injection.md`.
+Authoritative developer guide: `docs/dev-guides/6-i18n-language-injection.md`.
-> **Prerequisites**: Read `dev-guides/6-i18n-language-injection.md` before changing Agent prompts, Agent routes, backend user-visible messages, or frontend i18n strings.
+> **Prerequisites**: Read `docs/dev-guides/6-i18n-language-injection.md` before changing Agent prompts, Agent routes, backend user-visible messages, or frontend i18n strings.
> If your work introduces new language injection patterns or conventions, update this file and related dev-guides accordingly.
## Architecture
diff --git a/.cursor/skills/path-safety/SKILL.md b/.cursor/skills/path-safety/SKILL.md
index 7704d064..f93cf8fa 100644
--- a/.cursor/skills/path-safety/SKILL.md
+++ b/.cursor/skills/path-safety/SKILL.md
@@ -5,7 +5,7 @@ description: 服务端路径安全与文件访问编码规范。在编写文件
# Path Safety — 服务端安全编码规范
-> **来源**:`dev-guides/8-path-safety.md`(正式开发规范)+ `design-docs/issues/002-arbitrary-file-read-audit.md`(安全审计复核)。
+> **来源**:`docs/dev-guides/8-path-safety.md`(正式开发规范)+ `design-docs/issues/002-arbitrary-file-read-audit.md`(安全审计复核)。
> 本文档提炼了 6 条必须遵守的编码规范。违反任一条即可能引入路径穿越(LFI)漏洞。
---
@@ -154,7 +154,7 @@ def _enforce_deployment_restrictions():
## 参考文档
-- `dev-guides/8-path-safety.md` — 服务端路径安全开发规范
+- `docs/dev-guides/8-path-safety.md` — 服务端路径安全开发规范
- `design-docs/6-path-safety-confined-dir.md` — 剩余未完成实现项状态页
- `design-docs/issues/002-arbitrary-file-read-audit.md` — 安全审计复核报告
- `py-src/data_formulator/security/path_safety.py` — ConfinedDir 源码
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index 2db60c86..6ae19d08 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -527,7 +527,7 @@ cp -r /backup/workspaces $DATA_FORMULATOR_HOME/workspaces
> **Tip:** If you forgot to back up `FLASK_SECRET_KEY` and it was auto-generated, there is no way to recover it. Users will need to log in again, and any chart with a cached code signature will need to be re-executed by the Agent.
-> **中文版:** 详细的迁移操作指南见 [docs-cn/7-server-migration-guide.md](docs-cn/7-server-migration-guide.md)。
+> **中文版:** 详细的迁移操作指南见 [docs/docs-cn/7-server-migration-guide.md](docs/docs-cn/7-server-migration-guide.md)。
## Authentication Architecture
diff --git a/README.md b/README.md
index 1d8f697f..8e88cc9f 100644
--- a/README.md
+++ b/README.md
@@ -26,21 +26,35 @@
+
+## Why Data Formulator?
+
+Your data lives everywhere — databases, warehouses, BI tools, files. Coding agents can help, but only after someone wires them up, and answers come back as walls of code or text that are hard to follow, refine, or share.
+
+Data Formulator makes it simple: **connect any data, ask anything, get charts you can edit, branch, and share** — all on one interactive, visual canvas.
+
+- **Data & platform teams**: wire up your databases, warehouses, and BI sources once, and give the whole org an AI-powered data exploration layer.
+- **Analysts & users**: ask, edit, branch, share. It's so easy to get insights from good-looking charts.
+
-
## News 🔥🔥🔥
-[05-11-2026] **Data Formulator 0.7 (alpha 2)** — A new chapter for AI-powered data exploration
-- 🔌 **Data connectors** — first-class persistent connection to Superset, Kusto, Cosmos DB, MySQL, PostgreSQL, MSSQL, S3, Azure Blob, BigQuery, and more, with SSO, lazy catalog loading, search, and smart filters.
-- 💬 **Conversational agent with thread memory** — a unified `DataAgent` that weaves explanation, exploration, visualization, and recommendation into one fluid conversation, carrying context across turns so the agent stays in sync with your train of thought.
-- 🗂️ **Persistent session & workspace management** — identity-isolated workspaces with local and Azure Blob backends; sessions persist across restarts with timestamps and sort.
-- 📊 **Expressive visualization** — 30+ chart types via a new semantic chart engine (area, streamgraph, candlestick, pie, radar, maps, …), plus a chart style-refinement agent that turns rough charts into presentation-ready visuals: restyle in one click, refine typography, color, layout, and annotations through natural language.
-- 📚 **Knowledge distillation (experimental)** — agents distill reusable skills and experiences from your sessions into a shared knowledge library that informs future sessions.
+[05-28-2026] **Data Formulator 0.7** — turn ANY data into insights in five easy steps:
+
+1. **Connect.** Governed, reusable connections to databases, warehouses, BI systems, object stores, and files (Superset, Kusto, Cosmos DB, MySQL, PostgreSQL, MSSQL, BigQuery, S3, Azure Blob, …). Need a custom source? Point your coding agent at the [data loader plugin guide](examples/plugins/README.md).
+2. **Load.** Ask the **data-loading agent** to find tables from connected databases, or extract data from Excel files, images, websites, and text.
+3. **Explore.** A unified **Data Agent** with thread memory inspects data, runs sandboxed code, and weaves explanation, exploration, and recommendation into one fluid conversation — grounded in your context. The **Data Thread** keeps questions, intermediate results, and charts navigable: revisit earlier steps, branch into alternatives, and compare side by side.
+4. **Refine.** 30+ chart types (area, streamgraph, candlestick, radar, maps, KPI, …) via a new semantic chart engine, plus a **style-refinement agent** that turns rough charts into presentation-ready visuals through natural language.
+5. **Share.** Build reports and export as image or PDF to tell the story.
+
+➕ **Persistent sessions & workspaces** — identity-isolated, saved across restarts. Data Formulator is your de facto data analysis pane.
-> Install the pre-release with `pip install --pre data-formulator` or pin `==0.7.0a2`.
+**Multilingual UI** — Data Formulator now speaks Chinese in addition to English (没错,DF现在会说中文了!). More languages on the way — [contributions welcome](src/i18n/TRANSLATION_GUIDE.md).
+
+> Install with `pip install data_formulator` or run instantly with `uvx data_formulator`.
> [!TIP]
> **Are you a developer?** Join us to shape the future of AI-powered data exploration!
@@ -50,6 +64,7 @@ https://github.com/user-attachments/assets/8ca57b68-4d7a-42cb-bcce-43f8b1681ce2
## Previous Updates
Here are milestones that lead to the current design:
+- **v0.7 alpha 2** (05-11-2026): Early preview of data connectors, the unified `DataAgent` with thread memory, persistent workspaces, the semantic chart engine, and experimental knowledge distillation.
- **v0.6** ([Demo](https://github.com/microsoft/data-formulator/releases/tag/0.6)): Real-time insights from live data — connect to URLs and databases with automatic refresh
- **uv support**: Faster installation with [uv](https://docs.astral.sh/uv/) — `uvx data_formulator` or `uv pip install data_formulator`
- **v0.5.1** ([Demo](https://github.com/microsoft/data-formulator/pull/200#issue-3635408217)): Community data loaders, US Map & Pie Chart, editable reports, snappier UI
@@ -67,9 +82,7 @@ Here are milestones that lead to the current design:
## Overview
-**Data Formulator** is a Microsoft Research prototype for data exploration with visualizations powered by AI agents.
-
-Data Formulator enables analysts to explore data with visualizations. Started with data in any format (screenshot, text, csv, or database), you can work with AI agents with a novel blended interface that combines *user interface interactions (UI)* and *natural language (NL) inputs* to communicate their intents, control branching exploration directions, and create reports to share their insights.
+**Data Formulator** is a Microsoft Research project for data exploration with visualizations powered by AI agents. It combines *UI interactions* with *natural language* so analysts can communicate intent, branch into alternative analyses, and share results — starting from any data format (screenshot, text, CSV, or database).
## Get Started
diff --git a/dev-guides/1-streaming-protocol.md b/docs/dev-guides/1-streaming-protocol.md
similarity index 96%
rename from dev-guides/1-streaming-protocol.md
rename to docs/dev-guides/1-streaming-protocol.md
index 4885483f..dc9a7521 100644
--- a/dev-guides/1-streaming-protocol.md
+++ b/docs/dev-guides/1-streaming-protocol.md
@@ -34,7 +34,6 @@
| `get-recommendation-questions` | `"question"` | 探索建议问题 |
| `generate-report-chat` | `"text_delta"`, `"embed_chart"`, `"embed_table"` | 报告生成流 |
| `data-loading-chat` | `"text_delta"`, `"tool_call"`, `"tool_result"`, `"done"` | 数据加载对话 |
-| `clean-data-stream` | 各种 agent 事件 | 数据清洗流 |
| (跨端点通用) | `"thinking_text"` | Agent 推理/思考过程文本(参见 2.4) |
`data-agent-streaming` 的 `result.type === "clarify"` 使用结构化多问题格式。后端和前端都以
@@ -177,7 +176,7 @@ Agent 在执行过程中产生的推理/思考文本。前端应实时展示为
1. **Agent 层面的 think tool**:`DataAgent` 使用 `think` 工具时,将 tool message 以 `thinking_text` 事件输出。
2. **LLM 伴随内容**:当 LLM 在 tool_calls 旁返回文本 content 时,Route 层将其作为 `thinking_text` 事件输出。
-3. **(Phase 2/3)模型原生推理**:Anthropic extended thinking 或 OpenAI reasoning tokens(`reasoning_content` 字段),由 `client_utils.py` 解析后输出为 `thinking_text` 事件。
+3. **模型原生推理链保持**:部分推理模型(当前为 DeepSeek V4)在响应中返回 `reasoning_content` 字段,该字段在多轮对话中必须回传至 assistant 消息。已通过 `agent_utils.attach_reasoning_content()` 和 `accumulate_reasoning_content()` 在所有 tool-loop agent 中统一处理。未来 Anthropic extended thinking 或 OpenAI reasoning tokens 如需类似处理,可复用同一机制。
**后端生成**:
@@ -272,7 +271,6 @@ if (parsed.text) { ... }
| `/get-recommendation-questions` | `x-ndjson` | route 累积碎片 → `_try_parse_explore_line` | `stream_error_event` | ✅ `_with_warnings` |
| `/generate-report-chat` | `x-ndjson` | route `json.dumps(event)` | `stream_error_event` | ✅ `_with_warnings` |
| `/data-loading-chat` | `x-ndjson` | route `json.dumps(event)` | `stream_error_event` | ✅ `_with_warnings` |
-| `/clean-data-stream` | `x-ndjson` | agent 直接 yield | `stream_error_event` | ✅ `_with_warnings` |
> **注意**: `/refine-data` 曾出现在此表中,但实际实现为普通 JSON endpoint(`jsonify` 返回),不使用 NDJSON 流。已于 2026-04-30 Phase 0 盘点中确认并移除。详见 `design-docs/20` 附录 A.10。
diff --git a/dev-guides/10-agent-knowledge-reasoning-log.md b/docs/dev-guides/10-agent-knowledge-reasoning-log.md
similarity index 100%
rename from dev-guides/10-agent-knowledge-reasoning-log.md
rename to docs/dev-guides/10-agent-knowledge-reasoning-log.md
diff --git a/dev-guides/11-catalog-metadata-sync.md b/docs/dev-guides/11-catalog-metadata-sync.md
similarity index 100%
rename from dev-guides/11-catalog-metadata-sync.md
rename to docs/dev-guides/11-catalog-metadata-sync.md
diff --git a/dev-guides/12-sandbox-session.md b/docs/dev-guides/12-sandbox-session.md
similarity index 100%
rename from dev-guides/12-sandbox-session.md
rename to docs/dev-guides/12-sandbox-session.md
diff --git a/dev-guides/13-unified-row-limits.md b/docs/dev-guides/13-unified-row-limits.md
similarity index 100%
rename from dev-guides/13-unified-row-limits.md
rename to docs/dev-guides/13-unified-row-limits.md
diff --git a/docs/dev-guides/14-model-capability-runtime-degradation.md b/docs/dev-guides/14-model-capability-runtime-degradation.md
new file mode 100644
index 00000000..3d795ebe
--- /dev/null
+++ b/docs/dev-guides/14-model-capability-runtime-degradation.md
@@ -0,0 +1,136 @@
+# 14 - 模型能力运行时降级架构
+
+## 概述
+
+所有 LLM 调用统一通过 LiteLLM,利用 `drop_params=True` 实现运行时自动降级。
+前端和后端不再预判模型能力(vision、reasoning 等),而是让模型调用自然失败后自动重试。
+
+## 核心设计原则
+
+1. **唯一调用路径** — 所有 Agent 通过 `Client.get_completion()` 或 `Client.get_completion_with_tools()` 调用 LLM,两者内部均走 `litellm.completion()`。
+2. **`drop_params=True`** — LiteLLM 自动丢弃模型不支持的参数(如 `reasoning_effort`、`parallel_tool_calls`),不会报错。
+3. **图片降级** — 如果模型不支持图片,`_is_image_deserialize_error()` 捕获异常后自动剥离图片重试。
+4. **无前端预检查** — 前端始终允许用户上传图片;后端自动处理。
+
+## Client API
+
+```python
+class Client:
+ def get_completion(self, messages, stream=False,
+ reasoning_effort="low", **kwargs):
+ """通用 completion 调用。"""
+
+ def get_completion_with_tools(self, messages, tools, stream=False,
+ reasoning_effort="low", **kwargs):
+ """带 tools 的 completion 调用。接受 tool_choice、
+ parallel_tool_calls 等通过 **kwargs 传入。"""
+```
+
+两个方法共享相同的内部逻辑:
+- 拷贝 `self.params`,注入 `reasoning_effort`
+- 调用 `litellm.completion(model=..., drop_params=True, ...)`
+- 捕获 image deserialize 错误 → 剥离图片 → 重试
+
+## reasoning_effort 分层
+
+每个 Agent 的默认 tier 在 `py-src/data_formulator/agent_config.py` 的
+`AGENT_REASONING_EFFORT` 字典里统一维护。Agent 调用 LLM 时通过
+`reasoning_effort_for(_AGENT_ID, self.client.model)` 解析最终值,自动按
+目标模型做能力降级。
+
+### 五档定义
+
+| Tier | 适用范围 | 不支持的模型如何降级 |
+|---|---|---|
+| `none` | 仅 GPT-5 `codex` / `pro`(最轻档) | 其它模型回退到 `low` |
+| `minimal` | 仅 OpenAI GPT-5 base / mini / nano / 5.x | GPT-5 codex/pro → `none`;其它 → `low` |
+| `low` / `medium` / `high` | 所有支持 reasoning 的模型(LiteLLM 统一映射) | 不支持 reasoning 的模型由 `drop_params=True` 静默忽略 |
+
+> 选择原则:**挑能产出可接受质量的最低档**。重型代码生成 / 多步工具
+> 调用使用 `low`;单轮抽取 / 分类 / 格式化使用 `minimal`。
+
+### 当前配置(来源:`agent_config.py`)
+
+| Agent ID | Tier | 备注 |
+|---|---|---|
+| `data_transform` | `low` | 生成 Python 转换脚本 |
+| `data_rec` | `low` | 图表 / 转换推荐 |
+| `data_agent` | `low` | 多步探索 agent |
+| `report_gen` | `low` | 叙述 + inspect/embed 工具 |
+| `interactive_explore` | `low` | 探索想法 agent |
+| `data_loading_chat` | `low` | 会话式数据加载(带工具) |
+| `data_load` | `minimal` | 一次性类型推断 |
+| `experience_distill` | `minimal` | 总结分析上下文 |
+| `chart_insight` | `minimal` | 图表标题 + 1–3 个 takeaway |
+| `chart_restyle` | `minimal` | 对 Vega-Lite spec 做样式编辑 |
+| `code_explanation` | `minimal` | 解释衍生字段 |
+| `sort_data` | `minimal` | 小列表的自然顺序排序 |
+| `simple` | `minimal` | nl_to_filter / workspace_name / intent |
+
+`DEFAULT_REASONING_EFFORT = "low"` —— 未在表中列出的 agent id 走默认值。
+
+### 运行时覆盖
+
+通过环境变量 `DF_REASONING_EFFORT_` 可在不改代码的情况下临时
+调整某个 agent 的 tier:
+
+```bash
+DF_REASONING_EFFORT_DATA_TRANSFORM=medium
+DF_REASONING_EFFORT_REPORT_GEN=high
+```
+
+合法取值:`none` / `minimal` / `low` / `medium` / `high`。
+
+### Agent 调用模板
+
+```python
+from data_formulator.agent_config import reasoning_effort_for
+
+_AGENT_ID = "data_transform"
+
+response = self.client.get_completion(
+ messages=messages,
+ reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model),
+)
+```
+
+### 查询方式
+
+```bash
+# 当前所有 agent 的默认 tier
+grep -nE '"\w+": +"' py-src/data_formulator/agent_config.py
+
+# 所有调用点
+grep -rn 'reasoning_effort_for' py-src/data_formulator/agents/
+```
+
+## 已删除的机制
+
+| 删除项 | 原位置 | 理由 |
+|---|---|---|
+| `import openai` + 直连分支 | `client_utils.py`、5 个 Agent | 统一走 LiteLLM |
+| `get_response()` | `client_utils.py` | 死代码 |
+| `is_likely_text_only_model()` | `model_registry.py` | 硬编码模型名检查 |
+| `model_supports_vision()` | `model_registry.py` | 前端/路由不再预检查 |
+| `supports_vision` 字段 | `ModelConfig` (dfSlice)、`_reload`/`list_public` | 前端不消费 |
+| `checkIsLikelyTextOnlyModel()` | `DataLoadingChat.tsx` | 前端不预检查 |
+| `checkModelSupportsImageInput()` | `DataLoadingChat.tsx` | 前端不预检查 |
+| vision 路由预检查 | `routes/agents.py` chart-insight、data-loading-chat | 改为运行时降级 |
+
+## 新增 Agent 检查清单
+
+- [ ] Agent 继承正确的 base class 并使用 `self.client`
+- [ ] 在 `agent_config.py` 的 `AGENT_REASONING_EFFORT` 中为新 agent_id 设置默认 tier
+- [ ] 调用 LLM 时使用 `reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model)`
+- [ ] 需要 tools → 使用 `self.client.get_completion_with_tools(messages, tools, ...)`
+- [ ] **不要** 直接 `import litellm` 或 `import openai` 调用 API
+- [ ] **不要** 检查模型名来决定是否支持某功能(vision / reasoning 等)
+- [ ] **不要** 在调用点硬编码 `reasoning_effort="high"`——统一通过 `agent_config.py` 维护
+
+## 厂商映射
+
+| 厂商 | `reasoning_effort` 效果 |
+|---|---|
+| OpenAI (o1/o3/gpt-5) | 直接透传 |
+| Anthropic (Claude) | 映射为 `thinking.budget_tokens` |
+| 其他(Gemini、Ollama 等) | `drop_params=True` 静默忽略 |
diff --git a/docs/dev-guides/15-dataframe-serialization.md b/docs/dev-guides/15-dataframe-serialization.md
new file mode 100644
index 00000000..50271d64
--- /dev/null
+++ b/docs/dev-guides/15-dataframe-serialization.md
@@ -0,0 +1,54 @@
+# 15 — DataFrame Serialization Convention
+
+## Problem
+
+pandas `DataFrame.to_json(orient='records')` defaults to `date_format='epoch'`,
+which serializes `datetime64` columns as **epoch milliseconds** (e.g.
+`1773532800000`). When the frontend receives these numbers, `formatCellValue`
+treats them as plain integers and displays `1,773,532,800,000` instead of a
+formatted date.
+
+`DataFrame.to_dict(orient='records')` is even worse — it returns Python
+`pd.Timestamp` objects that are not JSON-serializable at all and rely on
+whatever `json.dumps` fallback happens to be in scope.
+
+## Solution
+
+A single utility function in `data_formulator.datalake.parquet_utils`:
+
+```python
+def df_to_safe_records(df: pd.DataFrame) -> list[dict[str, Any]]:
+ return json.loads(
+ df.to_json(orient="records", date_format="iso", default_handler=str)
+ )
+```
+
+For Arrow tables, the existing `get_sample_rows_from_arrow(table)` already
+handles this correctly via `make_json_safe`.
+
+## When to Use
+
+| Scenario | Function |
+|---|---|
+| Agent result rows (`content["rows"]`) | `df_to_safe_records(query_output)` |
+| Table sample rows (`sample_rows`) | `df_to_safe_records(sample_df)` |
+| Data loader metadata previews | `df_to_safe_records(df.head(5))` |
+| File parse results (Excel/CSV) | `df_to_safe_records(df)` |
+| Arrow table samples | `get_sample_rows_from_arrow(table)` |
+
+## Exceptions
+
+The following uses of `to_dict(orient='records')` are exempt because they never
+reach JSON serialization or the frontend:
+
+- **Kusto SDK metadata** — `.show tables details` results iterated in Python only
+- **Vega-Lite spec construction** — `create_vl_plots.py` builds inline data for
+ Vega specs; Vega handles temporal formatting itself
+
+## New Module Checklist
+
+When writing a new Agent, DataLoader, or route that returns DataFrame rows:
+
+1. Import: `from data_formulator.datalake.parquet_utils import df_to_safe_records`
+2. Convert: `rows = df_to_safe_records(df)` (not `to_json` / `to_dict`)
+3. Test: verify datetime columns appear as ISO strings in the response
diff --git a/dev-guides/2-log-sanitization.md b/docs/dev-guides/2-log-sanitization.md
similarity index 100%
rename from dev-guides/2-log-sanitization.md
rename to docs/dev-guides/2-log-sanitization.md
diff --git a/dev-guides/3-data-loader-development.md b/docs/dev-guides/3-data-loader-development.md
similarity index 98%
rename from dev-guides/3-data-loader-development.md
rename to docs/dev-guides/3-data-loader-development.md
index 481cae55..7f5db97c 100644
--- a/dev-guides/3-data-loader-development.md
+++ b/docs/dev-guides/3-data-loader-development.md
@@ -249,7 +249,7 @@ Loader type 注册后,`DataConnector` 会自动把它包装成 connector insta
1. **内置 loader**:修改源码,在 `data_loader/__init__.py` 的 `_LOADER_SPECS`
列表中添加 `(registry_key, module_path, class_name, pip_package)` 条目。
2. **外部 loader 插件**:不修改仓库源码,把 `*_data_loader.py` 放到
- `DF_PLUGIN_DIR` 指向的目录。默认目录是 `~/.data-formulator/plugins/`。
+ `DF_PLUGIN_DIR` 指向的目录。默认目录是 `~/.data_formulator/plugins/`。
内置 loader 当前**不是**包内自动发现;新增内置 loader 必须显式更新 `_LOADER_SPECS`。
零源码修改只适用于外部 `DF_PLUGIN_DIR` 插件。
@@ -315,7 +315,8 @@ my_report_data_loader.py -> my_report
- [ ] 大目录优先实现 `ls(path, filter, limit, offset)` 与 `search_catalog(query)`,避免前端展开时全量扫描。
- [ ] table 节点携带稳定源标识符,例如 `metadata["_source_name"]`,供 preview/import/refresh 使用。
- [ ] `fetch_data_as_arrow()` 尊重 `import_options` 中的 `size`、`columns`、`sort_columns`、`sort_order`、`filters`、`source_filters`。
-- [ ] `size` 必须通过 `min(opts.get("size", MAX_IMPORT_ROWS), MAX_IMPORT_ROWS)` 截断,从 `external_data_loader` 导入 `MAX_IMPORT_ROWS`。详见 `dev-guides/13-unified-row-limits.md`。
+- [ ] `sample_rows` 等面向前端的 DataFrame→records 转换使用 `df_to_safe_records(df)` 而非 `to_json`/`to_dict`(详见 `docs/dev-guides/15-dataframe-serialization.md`)。
+- [ ] `size` 必须通过 `min(opts.get("size", MAX_IMPORT_ROWS), MAX_IMPORT_ROWS)` 截断,从 `external_data_loader` 导入 `MAX_IMPORT_ROWS`。详见 `docs/dev-guides/13-unified-row-limits.md`。
- [ ] SQL 类 loader 构造筛选条件时使用参数化、标识符白名单或受控运算符集合,禁止拼接未校验的 operator/column。
**可靠性与测试**
@@ -450,7 +451,7 @@ Loader 应在 SQL 构建时使用参数化或白名单校验运算符(参考 `
- 连接和读取错误必须抛出清晰的 `ValueError`
- 表名/对象名需校验或清洗
- `fetch_data_as_arrow` 必须尊重 `import_options` 中的 `size`、`columns`、`sort_columns`、`sort_order`、`filters`、`source_filters`
-- `size` 参数必须受 `MAX_IMPORT_ROWS`(200 万)硬上限约束,防止意外 OOM(参见 `dev-guides/13-unified-row-limits.md`)
+- `size` 参数必须受 `MAX_IMPORT_ROWS`(200 万)硬上限约束,防止意外 OOM(参见 `docs/dev-guides/13-unified-row-limits.md`)
- `list_tables()` 返回值必须包含统一的轻量 metadata 字段(至少稳定源标识、列名/类型;有低成本来源时包含表/列描述)
- 覆盖 `get_column_types()` 或 `get_metadata()` 时,测试表级 `description`、列级 `description`、空描述清空、缺 key 保留和 metadata 失败不阻断导入/预览
diff --git a/dev-guides/4-authentication-oidc-tokenstore.md b/docs/dev-guides/4-authentication-oidc-tokenstore.md
similarity index 99%
rename from dev-guides/4-authentication-oidc-tokenstore.md
rename to docs/dev-guides/4-authentication-oidc-tokenstore.md
index 870bdaa5..4565edac 100644
--- a/dev-guides/4-authentication-oidc-tokenstore.md
+++ b/docs/dev-guides/4-authentication-oidc-tokenstore.md
@@ -140,7 +140,7 @@ def auth_config() -> dict:
- 前端收到消息后调用 `POST /api/auth/tokens/save`,请求体包含 `system_id`、`access_token`、可选 `refresh_token`、`user`、`remember`。
- Loader 的 `__init__` 必须消费注入的 `access_token` 或 `sso_access_token`,否则声明 delegated/SSO 模式没有实际效果。
-用户或运维侧 Superset 配置步骤见 `docs-cn/5.1-superset-sso-oauth-config-guide.md`。
+用户或运维侧 Superset 配置步骤见 `docs/docs-cn/5.1-superset-sso-oauth-config-guide.md`。
---
diff --git a/dev-guides/5-data-connector-api.md b/docs/dev-guides/5-data-connector-api.md
similarity index 96%
rename from dev-guides/5-data-connector-api.md
rename to docs/dev-guides/5-data-connector-api.md
index ca3a4c64..37d99602 100644
--- a/dev-guides/5-data-connector-api.md
+++ b/docs/dev-guides/5-data-connector-api.md
@@ -193,7 +193,7 @@ Vault 凭证同样按 `identity + connector_id` 隔离。两个用户连接同
Loader type discovery 来自 `DATA_LOADERS`:
- 内置 loader 在 `data_loader/__init__.py` 的 `_LOADER_SPECS` 中注册。
-- 外部 loader 从 `DF_PLUGIN_DIR` 扫描,默认目录为 `~/.data-formulator/plugins/`。
+- 外部 loader 从 `DF_PLUGIN_DIR` 扫描,默认目录为 `~/.data_formulator/plugins/`。
- 文件名必须匹配 `*_data_loader.py`,例如 `my_report_data_loader.py` 会注册为
`my_report`。
- 文件中需要定义公开的 `ExternalDataLoader` 子类;如果 key 与内置 loader 相同,
@@ -261,7 +261,7 @@ metadata 时,前端继续调用 `/api/connectors/get-catalog` 并传入该节
`design-docs/2-external-dataloader-enhancements.md` 的“缺陷二:认证方式单一,
缺少 SSO/集成认证”。
-认证相关细节见 `dev-guides/4-authentication-oidc-tokenstore.md`。
+认证相关细节见 `docs/dev-guides/4-authentication-oidc-tokenstore.md`。
---
@@ -302,11 +302,11 @@ Superset dashboard。成员表放在节点 `metadata["tables"]` 中。
`import-group` 会遍历请求中的 `tables`,为每个成员表单独写入 workspace。
每张表的行数受全局 `MAX_IMPORT_ROWS`(200 万)硬上限约束(前端不再传 `row_limit`,
-由后端 DataLoader 统一使用 `frontendRowLimit`;详见 `dev-guides/13-unified-row-limits.md`)。
+由后端 DataLoader 统一使用 `frontendRowLimit`;详见 `docs/dev-guides/13-unified-row-limits.md`)。
若传入 `source_filters`,只把 `applies_to` 命中的筛选条件传给对应成员表。
`source_filters` 是数据源原生筛选条件,不等同于通用前端 WHERE 构造器。格式与
-`dev-guides/3-data-loader-development.md` 保持一致:
+`docs/dev-guides/3-data-loader-development.md` 保持一致:
```json
[
@@ -359,8 +359,8 @@ Loader 应在 `fetch_data_as_arrow(source_table, import_options)` 中读取
## 14. 相关文档
-- `dev-guides/3-data-loader-development.md`
-- `dev-guides/4-authentication-oidc-tokenstore.md`
-- `docs-cn/1-data-source-connections.md`
-- `docs-cn/6-credential-vault.md`
-- `docs-cn/7-server-migration-guide.md`
+- `docs/dev-guides/3-data-loader-development.md`
+- `docs/dev-guides/4-authentication-oidc-tokenstore.md`
+- `docs/docs-cn/1-data-source-connections.md`
+- `docs/docs-cn/6-credential-vault.md`
+- `docs/docs-cn/7-server-migration-guide.md`
diff --git a/dev-guides/6-i18n-language-injection.md b/docs/dev-guides/6-i18n-language-injection.md
similarity index 98%
rename from dev-guides/6-i18n-language-injection.md
rename to docs/dev-guides/6-i18n-language-injection.md
index cfb4c8e0..15001b11 100644
--- a/dev-guides/6-i18n-language-injection.md
+++ b/docs/dev-guides/6-i18n-language-injection.md
@@ -95,10 +95,12 @@ agent = SortDataAgent(client=client, language_instruction=language_instruction)
| 场景 | Mode |
|------|------|
| `DataAgent`、`ChartInsightAgent`、`InteractiveExploreAgent`、`ReportGenAgent` | `full` |
+| `CodeExplanationAgent`、`DataLoadingAgent` | `full` |
| `DataRecAgent`、`DataTransformationAgent`、`DataLoadAgent` | `compact` |
-| `SortDataAgent` | `compact` |
+| `SortDataAgent`、`ChartRestyleAgent` | `compact` |
| `workspace-name` | `full` |
| `test-model`、模型列表、纯状态检查 | 不注入 |
+| `nl-to-filter`、`classify-chart-intent` | 不注入(纯结构化输出) |
### 2.2 Agent 层
@@ -222,7 +224,6 @@ event = {
| `agent.noCodeBlock` | `DataRecAgent` / `DataTransformationAgent` |
| `agent.unexpectedError` | `DataRecAgent` fallback |
| `agent.codeExecError` | code execution fallback |
-| `agent.unableExtractTables` | `DataCleanAgentStream` |
| `agent.unableExtractScript` | `DataLoadAgent` / `SortDataAgent` |
| `agent.errorCallingModel` | `DataLoadingChatAgent` |
@@ -419,5 +420,5 @@ locale 文件和 `AVAILABLE_LANGUAGES` 都配置完成的语言,才应出现
- `.cursor/skills/language-injection/SKILL.md`
- `.cursor/rules/language-injection-conventions.mdc`
- `.cursor/rules/i18n-no-hardcoded-strings.mdc`
-- `dev-guides/1-streaming-protocol.md`
-- `dev-guides/7-unified-error-handling.md`
+- `docs/dev-guides/1-streaming-protocol.md`
+- `docs/dev-guides/7-unified-error-handling.md`
diff --git a/dev-guides/7-unified-error-handling.md b/docs/dev-guides/7-unified-error-handling.md
similarity index 99%
rename from dev-guides/7-unified-error-handling.md
rename to docs/dev-guides/7-unified-error-handling.md
index 59554dfb..2127fdc3 100644
--- a/dev-guides/7-unified-error-handling.md
+++ b/docs/dev-guides/7-unified-error-handling.md
@@ -191,7 +191,7 @@ return json_ok(data), 400 # json_ok 已返回 (Response, status_code)
## 3. 后端流式 API
-流式端点使用 NDJSON,详见 `dev-guides/1-streaming-protocol.md`。
+流式端点使用 NDJSON,详见 `docs/dev-guides/1-streaming-protocol.md`。
基本要求:
@@ -459,7 +459,7 @@ metadata 请求不要复制短客户端 abort 模式。
前端通过 `getErrorMessage(apiError)` 优先使用本地 i18n,缺失时回退到后端英文 `message`。
-普通后端固定消息如果不是 `AppError` 体系,优先参考 `dev-guides/6-i18n-language-injection.md` 的 `message_code` / `content_code` 规则。
+普通后端固定消息如果不是 `AppError` 体系,优先参考 `docs/dev-guides/6-i18n-language-injection.md` 的 `message_code` / `content_code` 规则。
## 6. 错误分类工具
diff --git a/dev-guides/8-path-safety.md b/docs/dev-guides/8-path-safety.md
similarity index 99%
rename from dev-guides/8-path-safety.md
rename to docs/dev-guides/8-path-safety.md
index 3d1ee749..ae74cd0a 100644
--- a/dev-guides/8-path-safety.md
+++ b/docs/dev-guides/8-path-safety.md
@@ -147,7 +147,7 @@ def _enforce_deployment_restrictions():
)
```
-`local_folder` 是当前参考实现。Data Loader 通用开发规范见 `dev-guides/3-data-loader-development.md`。
+`local_folder` 是当前参考实现。Data Loader 通用开发规范见 `docs/dev-guides/3-data-loader-development.md`。
## 7. Sandbox 部署
diff --git a/dev-guides/9-workspace-storage-architecture.md b/docs/dev-guides/9-workspace-storage-architecture.md
similarity index 96%
rename from dev-guides/9-workspace-storage-architecture.md
rename to docs/dev-guides/9-workspace-storage-architecture.md
index cb4af07d..ef3ecffb 100644
--- a/dev-guides/9-workspace-storage-architecture.md
+++ b/docs/dev-guides/9-workspace-storage-architecture.md
@@ -55,6 +55,12 @@ DATA_FORMULATOR_HOME/ # 默认 ~/.data_formulator,可
**大小**: ~150 bytes
**写入时机**: `create_workspace()`, `save_session_state()`, `update_display_name()`
+`update_display_name()` 采用 write-through 策略:同时写 `workspace_meta.json` 和
+`session_state.json`(patch `activeWorkspace.displayName`),确保两个文件的 displayName
+始终一致——即使被重命名的 workspace 不是当前前端打开的那个。
+Azure Blob 后端因 session blob 可能好几 MB,下载+重上传开销大,不做 write-through;
+如果出现不一致,用户再改一次名字即可,下次 auto-save 会同步。
+
```json
{
"id": "session_20260426_212411_1503",
@@ -318,7 +324,7 @@ def _ensure_meta(self, workspace_id: str) -> dict:
- 适用于 `--disable-database` 模式(无服务端持久化)
- 默认行数限制为 20,000(`DEFAULT_ROW_LIMIT_EPHEMERAL`),以兼顾浏览器性能
-> **行数限制**: 两种模式的数据导入行数由统一的 `frontendRowLimit`(前端)和 `MAX_IMPORT_ROWS`(后端硬上限 200 万)控制。详见 `dev-guides/13-unified-row-limits.md`。
+> **行数限制**: 两种模式的数据导入行数由统一的 `frontendRowLimit`(前端)和 `MAX_IMPORT_ROWS`(后端硬上限 200 万)控制。详见 `docs/dev-guides/13-unified-row-limits.md`。
---
diff --git a/docs-cn/1-data-source-connections.md b/docs/docs-cn/1-data-source-connections.md
similarity index 98%
rename from docs-cn/1-data-source-connections.md
rename to docs/docs-cn/1-data-source-connections.md
index fd6de89e..2b5e38ce 100644
--- a/docs-cn/1-data-source-connections.md
+++ b/docs/docs-cn/1-data-source-connections.md
@@ -132,7 +132,7 @@ DATA_FORMULATOR_HOME/credentials.db
```
服务器迁移、备份或 Docker 部署时,这两个文件需要和用户数据一起保留。更多说明见
-`docs-cn/6-credential-vault.md` 和 `docs-cn/7-server-migration-guide.md`。
+`docs/docs-cn/6-credential-vault.md` 和 `docs/docs-cn/7-server-migration-guide.md`。
---
diff --git a/docs-cn/5-datasource_plugin-development-guide.md b/docs/docs-cn/5-datasource_plugin-development-guide.md
similarity index 96%
rename from docs-cn/5-datasource_plugin-development-guide.md
rename to docs/docs-cn/5-datasource_plugin-development-guide.md
index 9279c93a..80adc43d 100644
--- a/docs-cn/5-datasource_plugin-development-guide.md
+++ b/docs/docs-cn/5-datasource_plugin-development-guide.md
@@ -44,7 +44,7 @@ DF_PLUGIN_DIR # 不改源码外加 loader type 的目录
如果要接入一个全新的报表系统或内部数据服务,管理员可以提供一个外部 loader 文件:
```text
-~/.data-formulator/plugins/my_report_data_loader.py
+~/.data_formulator/plugins/my_report_data_loader.py
```
也可以通过环境变量指定目录:
@@ -225,7 +225,7 @@ DF_SOURCES__my_report_prod__params__url=https://report.example.com
| `delegated_login_config()` | 声明弹窗登录 URL 与按钮文案 |
| `auth_mode()` | 旧兼容接口,新 loader 优先使用 `auth_config()` |
-认证细节见 `dev-guides/4-authentication-oidc-tokenstore.md`。
+认证细节见 `docs/dev-guides/4-authentication-oidc-tokenstore.md`。
---
@@ -250,5 +250,5 @@ DF_SOURCES__my_report_prod__params__url=https://report.example.com
- [ ] 服务重启后,`GET /api/data-loaders` 能看到新的 loader type。
- [ ] Add Connection 能创建连接,preview/import/refresh 能正常工作。
-更多开发细节见 [dev-guides/3-data-loader-development.md](../dev-guides/3-data-loader-development.md)
-和 [dev-guides/5-data-connector-api.md](../dev-guides/5-data-connector-api.md)。
+更多开发细节见 [docs/dev-guides/3-data-loader-development.md](../dev-guides/3-data-loader-development.md)
+和 [docs/dev-guides/5-data-connector-api.md](../dev-guides/5-data-connector-api.md)。
diff --git a/docs-cn/5.1-superset-sso-oauth-config-guide.md b/docs/docs-cn/5.1-superset-sso-oauth-config-guide.md
similarity index 97%
rename from docs-cn/5.1-superset-sso-oauth-config-guide.md
rename to docs/docs-cn/5.1-superset-sso-oauth-config-guide.md
index e0b9e13a..6b62beff 100644
--- a/docs-cn/5.1-superset-sso-oauth-config-guide.md
+++ b/docs/docs-cn/5.1-superset-sso-oauth-config-guide.md
@@ -113,7 +113,7 @@ superset_config.py ← Superset 主配置(导入 oauth_config)
oauth_config.py ← SSO 认证 + DF 桥接(独立文件,便于维护)
```
-> **参考示例**:完整的配置示例文件见 [`docs-cn/config-examples/superset/`](config-examples/superset/),可作为起点按需修改。
+> **参考示例**:完整的配置示例文件见 [`docs/docs-cn/config-examples/superset/`](config-examples/superset/),可作为起点按需修改。
---
diff --git a/docs-cn/6-credential-vault.md b/docs/docs-cn/6-credential-vault.md
similarity index 91%
rename from docs-cn/6-credential-vault.md
rename to docs/docs-cn/6-credential-vault.md
index becc73b2..5c6d3f97 100644
--- a/docs-cn/6-credential-vault.md
+++ b/docs/docs-cn/6-credential-vault.md
@@ -39,7 +39,7 @@ DATA_FORMULATOR_HOME/users//connectors.yaml # 用户个人连接
```
这些文件在重启和升级后持续保留。迁移服务器时必须一起备份,详见
-`docs-cn/7-server-migration-guide.md`。
+`docs/docs-cn/7-server-migration-guide.md`。
---
@@ -114,7 +114,7 @@ service token 或通过 SSO exchange 获取目标系统 token。
5. 使用 vault 中保存的静态凭证。
6. 无可用凭证,提示用户重新授权或重新输入。
-开发细节见 `dev-guides/4-authentication-oidc-tokenstore.md`。
+开发细节见 `docs/dev-guides/4-authentication-oidc-tokenstore.md`。
---
@@ -174,6 +174,6 @@ py-src/data_formulator/credential_vault/
相关文档:
-- `docs-cn/1-data-source-connections.md`
-- `docs-cn/7-server-migration-guide.md`
-- `dev-guides/5-data-connector-api.md`
+- `docs/docs-cn/1-data-source-connections.md`
+- `docs/docs-cn/7-server-migration-guide.md`
+- `docs/dev-guides/5-data-connector-api.md`
diff --git a/docs-cn/7-server-migration-guide.md b/docs/docs-cn/7-server-migration-guide.md
similarity index 98%
rename from docs-cn/7-server-migration-guide.md
rename to docs/docs-cn/7-server-migration-guide.md
index 6162682c..9edc36e9 100644
--- a/docs-cn/7-server-migration-guide.md
+++ b/docs/docs-cn/7-server-migration-guide.md
@@ -240,5 +240,5 @@ Vault 加密密钥丢失后,已存储的凭证 **无法恢复**。处理方式
## 8. 相关文档
- [凭证保险箱(Credential Vault)](6-credential-vault.md) — Vault 加密机制详解
-- [DEVELOPMENT.md — Server Migration Checklist](../DEVELOPMENT.md) — 英文版迁移清单
-- [.env.template](../.env.template) — 完整配置项说明
+- [DEVELOPMENT.md — Server Migration Checklist](../../DEVELOPMENT.md) — 英文版迁移清单
+- [.env.template](../../.env.template) — 完整配置项说明
diff --git a/docs-cn/config-examples/superset/oauth_config.py b/docs/docs-cn/config-examples/superset/oauth_config.py
similarity index 100%
rename from docs-cn/config-examples/superset/oauth_config.py
rename to docs/docs-cn/config-examples/superset/oauth_config.py
diff --git a/docs-cn/config-examples/superset/superset_config.py b/docs/docs-cn/config-examples/superset/superset_config.py
similarity index 100%
rename from docs-cn/config-examples/superset/superset_config.py
rename to docs/docs-cn/config-examples/superset/superset_config.py
diff --git a/embed/README.md b/embed/README.md
deleted file mode 100644
index ce484d5b..00000000
--- a/embed/README.md
+++ /dev/null
@@ -1,85 +0,0 @@
-# Embed Data Formulator
-
-First you'll need to build the bundle:
-```
-yarn build
-```
-
-This puts the complete js file in the `dist` folder.
-
-## Test bundle
-
-Next you can test to see the complete Data Formulator app by opening `/embed/index.html` in your browser. You can do this by double-clicking in your file explorer (this would use the `file://` protocol).
-
-To test cross-frame messaging, launch `postMessageTest.html` which hosts the app in an iframe, and has buttons to send commands such as `load data`.
-
-## Use in Fabric Notebook
-
-You willl need to enable access to your `dist` from the cloud. There are 2 ways to do this:
-* Publish the `dist` (e.g. pip, npm, or other)
-* Create a tunnel to your localhost
-
-### Tunnel to localhost
-One way is to install [local-web-server](https://www.npmjs.com/package/local-web-server). This will serve a local folder as a website on http://localhost:8000. Next, you can set up a tunnel such as [ngrok](https://ngrok.com/download) which can provide a cloud-accesible url proxy to your local server.
-
-Copy the python function in a notebook cell:
-```py
-def dfviz(df, tableName, serverUrl):
- # df is a PySpark DataFrame
-
- import json
- from datetime import date, datetime
-
- # Custom function to convert datetime objects to string
- def json_serial(obj):
- if isinstance(obj, (datetime, date)):
- return obj.isoformat()
- raise TypeError ("Type %s not serializable" % type(obj))
-
- # Convert DataFrame rows to dictionaries and collect them into a list
- data = [row.asDict() for row in df.collect()]
-
- # Convert list of dictionaries to a single JSON array using the custom function
- json_data = json.dumps(data, default=json_serial)
-
- displayHTML(f"""
-
-
-"""
-)
-```
-
-Get a dataframe and pass it to the `dfviz` function:
-```py
-df = spark.sql("SELECT * FROM Sample_lakehouse_475.publicholidays LIMIT 100")
-display(df)
-dfviz(df, 'Holidays', 'https://')
-```
-
diff --git a/embed/dynamic.html b/embed/dynamic.html
deleted file mode 100644
index 02ebae7f..00000000
--- a/embed/dynamic.html
+++ /dev/null
@@ -1,110 +0,0 @@
-
-
-
-
-
-
- Data Formulator embedded dynamically
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/embed/index.html b/embed/index.html
deleted file mode 100644
index d81fe74d..00000000
--- a/embed/index.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
- Data Formulator embedded
-
-
-
-
-
-
\ No newline at end of file
diff --git a/embed/postMessageTest.html b/embed/postMessageTest.html
deleted file mode 100644
index c132d3ff..00000000
--- a/embed/postMessageTest.html
+++ /dev/null
@@ -1,116 +0,0 @@
-
-
-
-
-
-
- Data Formulator embedded iframe
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/plugins/README.md b/examples/plugins/README.md
new file mode 100644
index 00000000..2aa9a58e
--- /dev/null
+++ b/examples/plugins/README.md
@@ -0,0 +1,223 @@
+# Data Formulator — Data Loader Plugins
+
+Drop-in Python files that add new data-source connectors to Data
+Formulator without modifying its source code. If the built-in
+connectors don't cover your data source (an internal warehouse, a SaaS
+API, a niche database), write a small plugin and DF will pick it up on
+the next restart.
+
+This folder contains **example plugins**. Treat them as templates: copy
+one, rename it, and adapt the body.
+
+---
+
+## Quick start (3 steps)
+
+1. **Find your plugin directory.** It lives under your Data Formulator
+ home dir:
+
+ ```
+ $DATA_FORMULATOR_HOME/plugins/
+ ```
+
+ If `DATA_FORMULATOR_HOME` is not set, DF defaults to
+ `~/.data_formulator/`, so the plugin dir is `~/.data_formulator/plugins/`.
+
+ Power users can point somewhere else with `DF_PLUGIN_DIR`
+ (highest precedence) — useful for sharing one plugin folder across
+ multiple DF installs.
+
+2. **Copy an example into it.** For instance:
+
+ ```bash
+ mkdir -p "${DATA_FORMULATOR_HOME:-$HOME/.data_formulator}/plugins"
+ cp examples/plugins/sqlite_data_loader.py \
+ "${DATA_FORMULATOR_HOME:-$HOME/.data_formulator}/plugins/"
+ ```
+
+3. **Restart Data Formulator.** The new connector appears in the UI
+ automatically. No registry edits, no rebuilds.
+
+To verify it loaded, check the startup log for a line like:
+
+```
+INFO ... Plugin loader 'sqlite' registered from sqlite_data_loader.py
+INFO ... Plugin scan complete: 1 registered, 0 failed (dir=..., reason=WORKSPACE_BACKEND=local)
+```
+
+### Plugin directory resolution order
+
+| Precedence | Source | Default |
+| ---------- | ----------------------------------------- | ----------------------------- |
+| 1 | `DF_PLUGIN_DIR` env var (explicit override) | — |
+| 2 | `$DATA_FORMULATOR_HOME/plugins` | — |
+| 3 | Fallback | `~/.data_formulator/plugins/` |
+
+---
+
+## File-name contract
+
+| Filename | Registry key |
+| --------------------------------- | -------------- |
+| `sqlite_data_loader.py` | `sqlite` |
+| `acme_warehouse_data_loader.py` | `acme_warehouse` |
+| `notion_data_loader.py` | `notion` |
+
+Rules:
+
+* The filename **must** end in `_data_loader.py`.
+* The prefix becomes the registry key — keep it lowercase, no spaces.
+* If the key matches a built-in (e.g. `mysql_data_loader.py`), the
+ plugin **overrides** the built-in. Useful for hot-patching.
+
+---
+
+## What goes inside the file
+
+Each plugin defines exactly one class that subclasses
+[`ExternalDataLoader`](../../py-src/data_formulator/data_loader/external_data_loader.py).
+The minimum surface area:
+
+```python
+from data_formulator.data_loader.external_data_loader import (
+ ExternalDataLoader, MAX_IMPORT_ROWS,
+)
+import pyarrow as pa
+
+class MyLoader(ExternalDataLoader):
+
+ # Optional: human-friendly UI label. Without this, the registry key
+ # is title-cased (``"my_warehouse"`` → ``"My Warehouse"``). Override
+ # to fix awkward casing (``"SQLite"``, ``"BigQuery"``).
+ DISPLAY_NAME = "My Warehouse"
+
+ @staticmethod
+ def list_params() -> list[dict]:
+ """Declare connection-form fields. The UI auto-renders this."""
+ return [
+ {"name": "endpoint", "type": "string", "required": True,
+ "tier": "connection", "description": "Server URL"},
+ {"name": "token", "type": "string", "required": True,
+ "tier": "auth", "sensitive": True, "description": "API token"},
+ ]
+
+ @staticmethod
+ def auth_instructions() -> str:
+ """Markdown help text shown next to the form."""
+ return "Get your API token from https://example.com/settings/tokens"
+
+ def __init__(self, params: dict):
+ self.params = params
+ # validate + open connection here
+
+ def list_tables(self, table_filter: str | None = None) -> list[dict]:
+ """Return catalog: [{name, metadata: {columns, row_count}}, ...]"""
+ ...
+
+ def fetch_data_as_arrow(self, source_table: str,
+ import_options: dict | None = None) -> pa.Table:
+ """Read rows. Honour import_options['size'] up to MAX_IMPORT_ROWS."""
+ ...
+```
+
+Look at [`sqlite_data_loader.py`](sqlite_data_loader.py) for a runnable
+implementation (~170 lines, stdlib only).
+
+### `list_params()` field reference
+
+| Key | Meaning |
+| ------------- | ---------------------------------------------------------------- |
+| `name` | Parameter key passed into `__init__(params)` |
+| `type` | `"string"`, `"int"`, `"bool"`, `"password"` |
+| `required` | If `True`, DF rejects connections that omit it |
+| `default` | Pre-filled value in the form |
+| `sensitive` | If `True`, value is redacted from logs / stored metadata |
+| `tier` | `"auth"`, `"connection"`, or `"filter"` — groups fields visually |
+| `description` | Help text shown under the field |
+
+---
+
+## Security gate — please read
+
+Plugins execute arbitrary Python in the server process. To prevent
+accidental code execution in shared deployments, the plugin scanner is
+**enabled only in single-user local mode**:
+
+* `WORKSPACE_BACKEND` unset or `local` → scanner runs.
+* `WORKSPACE_BACKEND` is anything else → scanner is skipped silently.
+* To opt in for a hosted deployment, set `DF_ALLOW_PLUGINS=1`
+ **and** make sure the plugin directory is writable only by trusted
+ administrators.
+
+---
+
+## Debugging a plugin that won't load
+
+The scanner reports every failure two ways:
+
+1. **In the log**, with a full traceback:
+
+ ```
+ WARNING Failed to load plugin foo_data_loader.py: ... ModuleNotFoundError ...
+ ```
+
+2. **In `DISABLED_LOADERS`**, which the frontend surfaces as a greyed-out
+ connector with the reason. Common reasons:
+
+ | Message | Fix |
+ | ------------------------------------------------------ | --- |
+ | `missing dependency 'X' (pip install X)` | `uv pip install X` in DF's venv |
+ | `no ExternalDataLoader subclass found` | Add a `class Foo(ExternalDataLoader)` to the file |
+ | `could not create import spec` | File isn't valid Python or has wrong extension |
+ | `: ` | Anything else raised during `import` — check the traceback |
+
+The plugin scanner cleans `sys.modules` on failure, so simply restarting
+DF after editing the file picks up the fix — no manual cleanup needed.
+
+---
+
+## Adding third-party dependencies
+
+If your plugin needs a package that isn't already in DF's environment:
+
+```bash
+# from the data-formulator repo root
+uv pip install
+```
+
+The plugin file is loaded into the same Python process as DF, so
+anything importable from DF's venv is importable from your plugin.
+
+---
+
+## For AI coding agents
+
+When asked to **add a new data source** to a user's Data Formulator
+install, prefer writing a plugin file over modifying DF's source tree:
+
+1. Read [`sqlite_data_loader.py`](sqlite_data_loader.py) and the
+ `ExternalDataLoader` ABC in
+ `py-src/data_formulator/data_loader/external_data_loader.py` to
+ understand the required methods.
+2. Create a new file `_data_loader.py` in this folder (or
+ directly in `~/.data_formulator/plugins/`).
+3. Subclass `ExternalDataLoader`. Implement at minimum:
+ `list_params`, `auth_instructions`, `__init__`, `list_tables`,
+ `fetch_data_as_arrow`.
+4. Return data as a `pyarrow.Table` from `fetch_data_as_arrow` — do
+ **not** convert to pandas in the hot path.
+5. Quote identifiers when building SQL (see `_quote_ident` in the
+ SQLite example) to avoid injection vulnerabilities.
+6. Respect `import_options['size']` and cap at `MAX_IMPORT_ROWS`.
+7. If the source has credentials, mark those params `sensitive: True`
+ and `tier: "auth"` so DF redacts them from stored metadata.
+8. Do not modify the user's data — open read-only connections where
+ the source supports it.
+
+After writing the file, verify it loads with:
+
+```bash
+DF_PLUGIN_DIR= uv run python -c \
+ "from data_formulator import data_loader as dl; \
+ print(dl.PLUGIN_LOADERS, dl.DISABLED_LOADERS)"
+```
diff --git a/examples/plugins/sqlite_data_loader.py b/examples/plugins/sqlite_data_loader.py
new file mode 100644
index 00000000..cde32a82
--- /dev/null
+++ b/examples/plugins/sqlite_data_loader.py
@@ -0,0 +1,203 @@
+"""SQLite data loader — example plugin for Data Formulator.
+
+This file is a complete, working example of a Data Formulator plugin.
+SQLite is part of the Python standard library, so this loader has **no
+extra dependencies** and is a good template for building your own.
+
+How to install
+--------------
+1. Make sure Data Formulator runs in single-user mode
+ (the default — ``WORKSPACE_BACKEND`` unset or ``local``).
+2. Copy this file to ``~/.data_formulator/plugins/`` (or whatever
+ directory ``DF_PLUGIN_DIR`` points to). Filename must end in
+ ``_data_loader.py``.
+3. Restart Data Formulator. A new "sqlite" connector should appear
+ alongside the built-ins.
+
+How to test it quickly
+----------------------
+::
+
+ sqlite3 /tmp/demo.db <<'SQL'
+ CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER);
+ INSERT INTO users VALUES (1, 'Alice', 30), (2, 'Bob', 25);
+ SQL
+
+Then in DF, add a SQLite connector pointing at ``/tmp/demo.db``.
+
+What this example demonstrates
+------------------------------
+* Implementing every abstract method on :class:`ExternalDataLoader`.
+* Declaring connection params via :meth:`list_params` so the UI
+ auto-renders a config form.
+* Identifier quoting to avoid SQL-injection in table/column names.
+* Returning data directly as a PyArrow Table (no pandas in the hot path).
+* Read-only access (``mode=ro`` URI) — the loader never writes to the DB.
+"""
+
+from __future__ import annotations
+
+import logging
+import os
+import sqlite3
+import threading
+from typing import Any
+from urllib.parse import quote as _url_quote
+
+import pyarrow as pa
+
+from data_formulator.data_loader.external_data_loader import (
+ ExternalDataLoader,
+ MAX_IMPORT_ROWS,
+)
+
+logger = logging.getLogger(__name__)
+
+
+def _quote_ident(name: str) -> str:
+ """Quote a SQLite identifier safely (table or column name)."""
+ return '"' + str(name).replace('"', '""') + '"'
+
+
+class SQLiteDataLoader(ExternalDataLoader):
+ """Read tables from a local SQLite database file."""
+
+ # Override the default title-casing of the registry key ("Sqlite") with
+ # a properly-cased product name. Optional; remove if you don't care.
+ DISPLAY_NAME = "SQLite"
+
+ # ------------------------------------------------------------------ #
+ # Static metadata: what the UI shows + how to configure #
+ # ------------------------------------------------------------------ #
+
+ @staticmethod
+ def list_params() -> list[dict[str, Any]]:
+ return [
+ {
+ "name": "database_path",
+ "type": "string",
+ "required": True,
+ "default": "",
+ "tier": "connection",
+ "description": "Absolute path to a .db / .sqlite file",
+ },
+ ]
+
+ @staticmethod
+ def auth_instructions() -> str:
+ return (
+ "**Example:** `/tmp/demo.db`\n\n"
+ "Provide the absolute path to a local SQLite database file. "
+ "The file must exist and be readable. The loader opens it "
+ "read-only — your data is never modified.\n\n"
+ "**Create a test DB:**\n"
+ "```\nsqlite3 /tmp/demo.db 'CREATE TABLE t(a,b); "
+ "INSERT INTO t VALUES (1,2),(3,4);'\n```"
+ )
+
+ # ------------------------------------------------------------------ #
+ # Connection #
+ # ------------------------------------------------------------------ #
+
+ def __init__(self, params: dict[str, Any]):
+ self.params = params or {}
+ self.database_path = (self.params.get("database_path") or "").strip()
+
+ if not self.database_path:
+ raise ValueError("SQLite database_path is required")
+ if not os.path.isfile(self.database_path):
+ raise ValueError(f"SQLite database not found: {self.database_path}")
+
+ # Open read-only via URI so we cannot accidentally mutate the DB.
+ uri = f"file:{_url_quote(self.database_path)}?mode=ro"
+ try:
+ self._conn = sqlite3.connect(
+ uri, uri=True, check_same_thread=False, isolation_level=None,
+ )
+ except sqlite3.Error as e:
+ raise ValueError(
+ f"Failed to open SQLite database '{self.database_path}': {e}"
+ ) from e
+
+ self._lock = threading.Lock()
+ logger.info("SQLite plugin connected: %s", self.database_path)
+
+ # ------------------------------------------------------------------ #
+ # Helpers #
+ # ------------------------------------------------------------------ #
+
+ def _read_sql(self, query: str) -> pa.Table:
+ """Run a query and return the result as a PyArrow Table."""
+ with self._lock:
+ cur = self._conn.execute(query)
+ if cur.description is None:
+ return pa.table({})
+ columns = [d[0] for d in cur.description]
+ rows = cur.fetchall()
+ # Transpose rows to per-column lists; pyarrow infers types.
+ col_data: dict[str, list[Any]] = {c: [] for c in columns}
+ for row in rows:
+ for col, value in zip(columns, row):
+ col_data[col].append(value)
+ return pa.table(col_data)
+
+ # ------------------------------------------------------------------ #
+ # Required loader API #
+ # ------------------------------------------------------------------ #
+
+ def list_tables(self, table_filter: str | None = None) -> list[dict[str, Any]]:
+ """List every table + view in the database."""
+ names_tbl = self._read_sql(
+ "SELECT name, type FROM sqlite_master "
+ "WHERE type IN ('table', 'view') "
+ "AND name NOT LIKE 'sqlite_%' "
+ "ORDER BY name"
+ )
+ if names_tbl.num_rows == 0:
+ return []
+
+ results: list[dict[str, Any]] = []
+ for name in names_tbl.column("name").to_pylist():
+ if table_filter and table_filter.lower() not in name.lower():
+ continue
+ # PRAGMA table_info gives column name + declared type.
+ info = self._read_sql(f"PRAGMA table_info({_quote_ident(name)})")
+ columns = [
+ {"name": n, "type": t or "ANY"}
+ for n, t in zip(
+ info.column("name").to_pylist() if info.num_rows else [],
+ info.column("type").to_pylist() if info.num_rows else [],
+ )
+ ]
+ count_tbl = self._read_sql(
+ f"SELECT COUNT(*) AS n FROM {_quote_ident(name)}"
+ )
+ row_count = int(count_tbl.column("n")[0].as_py()) if count_tbl.num_rows else 0
+ results.append({
+ "name": name,
+ "metadata": {"columns": columns, "row_count": row_count},
+ })
+ return results
+
+ def fetch_data_as_arrow(
+ self,
+ source_table: str,
+ import_options: dict[str, Any] | None = None,
+ ) -> pa.Table:
+ """Fetch rows from ``source_table`` as a PyArrow Table."""
+ if not source_table:
+ raise ValueError("source_table must be provided")
+
+ opts = import_options or {}
+ size = min(int(opts.get("size", MAX_IMPORT_ROWS)), MAX_IMPORT_ROWS)
+ sort_columns = opts.get("sort_columns") or []
+ sort_order = "DESC" if str(opts.get("sort_order", "asc")).lower() == "desc" else "ASC"
+
+ query = f"SELECT * FROM {_quote_ident(source_table)}"
+ if sort_columns:
+ order_by = ", ".join(f"{_quote_ident(c)} {sort_order}" for c in sort_columns)
+ query += f" ORDER BY {order_by}"
+ query += f" LIMIT {int(size)}"
+
+ logger.info("SQLite plugin query: %s", query)
+ return self._read_sql(query)
diff --git a/package.json b/package.json
index 9e40746d..42c8e2bd 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,10 @@
"@mui/x-tree-view": "^9.0.1",
"@reduxjs/toolkit": "^1.8.6",
"@tiptap/extension-image": "^3.22.2",
+ "@tiptap/extension-table": "^3.23.6",
+ "@tiptap/extension-table-cell": "^3.23.6",
+ "@tiptap/extension-table-header": "^3.23.6",
+ "@tiptap/extension-table-row": "^3.23.6",
"@tiptap/pm": "^3.22.2",
"@tiptap/react": "^3.22.2",
"@tiptap/starter-kit": "^3.22.2",
@@ -48,7 +52,7 @@
"react": "^18.2.0",
"react-animate-height": "^3.0.4",
"react-animate-on-change": "^2.2.0",
- "react-arborist": "^3.5.0",
+ "react-arborist": "3.7.0",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.2.0",
diff --git a/public/climate-gas-indicator.xlsx b/public/climate-gas-indicator.xlsx
new file mode 100644
index 00000000..b936c18b
Binary files /dev/null and b/public/climate-gas-indicator.xlsx differ
diff --git a/public/df_global_energy.json b/public/df_global_energy.json
index 3c678f94..6b82ad5e 100644
--- a/public/df_global_energy.json
+++ b/public/df_global_energy.json
@@ -1 +1 @@
-{"tables": [{"kind": "table", "id": "global-energy-20-small.csv", "displayId": "energy-co2", "names": ["Year", "Entity", "Value_co2_emissions_kt_by_country", "Electricity from fossil fuels (TWh)", "Electricity from nuclear (TWh)", "Electricity from renewables (TWh)"], "metadata": {"Year": {"type": "number", "semanticType": "Year"}, "Entity": {"type": "string", "semanticType": "Location"}, "Value_co2_emissions_kt_by_country": {"type": "number", "semanticType": "Number"}, "Electricity from fossil fuels (TWh)": {"type": "number", "semanticType": "Number"}, "Electricity from nuclear (TWh)": {"type": "number", "semanticType": "Number"}, "Electricity from renewables (TWh)": {"type": "number", "semanticType": "Number"}}, "rows": [{"Year": 2000, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 339450, "Electricity from fossil fuels (TWh)": 181.05, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 17.11}, {"Year": 2001, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 345640, "Electricity from fossil fuels (TWh)": 194.33, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 17.4}, {"Year": 2002, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 353369.9951, "Electricity from fossil fuels (TWh)": 197.29, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 17.35}, {"Year": 2003, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 352579.9866, "Electricity from fossil fuels (TWh)": 195.13, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 18.5}, {"Year": 2004, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 365809.9976, "Electricity from fossil fuels (TWh)": 203.66, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 19.41}, {"Year": 2005, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 370089.9963, "Electricity from fossil fuels (TWh)": 195.95, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 19.75}, {"Year": 2006, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 375489.9902, "Electricity from fossil fuels (TWh)": 198.72, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 21.19}, {"Year": 2007, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 385750, "Electricity from fossil fuels (TWh)": 208.59, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 20.93}, {"Year": 2008, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 388940.0024, "Electricity from fossil fuels (TWh)": 211.06, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 18.49}, {"Year": 2009, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 395290.0085, "Electricity from fossil fuels (TWh)": 216.42, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 18.32}, {"Year": 2010, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 387540.0085, "Electricity from fossil fuels (TWh)": 212.5, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 21.13}, {"Year": 2011, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 386380.0049, "Electricity from fossil fuels (TWh)": 213.56, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 27.33}, {"Year": 2012, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 386970.0012, "Electricity from fossil fuels (TWh)": 206.75, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 26.63}, {"Year": 2013, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 380279.9988, "Electricity from fossil fuels (TWh)": 195.78, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 34.2}, {"Year": 2014, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 371630.0049, "Electricity from fossil fuels (TWh)": 205.46, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 36.15}, {"Year": 2015, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 377799.9878, "Electricity from fossil fuels (TWh)": 197.72, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 33.12}, {"Year": 2016, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 384989.9902, "Electricity from fossil fuels (TWh)": 207.66, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 38.41}, {"Year": 2017, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 389160.0037, "Electricity from fossil fuels (TWh)": 209.14, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 40.77}, {"Year": 2018, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 387070.0073, "Electricity from fossil fuels (TWh)": 207.45, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 42.93}, {"Year": 2019, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 386529.9988, "Electricity from fossil fuels (TWh)": 196.45, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 53.41}, {"Year": 2020, "Entity": "Australia", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 186.92, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 63.99}, {"Year": 2000, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 313670, "Electricity from fossil fuels (TWh)": 28.87, "Electricity from nuclear (TWh)": 4.94, "Electricity from renewables (TWh)": 308.77}, {"Year": 2001, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 319380, "Electricity from fossil fuels (TWh)": 35.19, "Electricity from nuclear (TWh)": 14.27, "Electricity from renewables (TWh)": 273.71}, {"Year": 2002, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 317760.0098, "Electricity from fossil fuels (TWh)": 33.5, "Electricity from nuclear (TWh)": 13.84, "Electricity from renewables (TWh)": 292.95}, {"Year": 2003, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 310809.9976, "Electricity from fossil fuels (TWh)": 31.62, "Electricity from nuclear (TWh)": 13.4, "Electricity from renewables (TWh)": 313.88}, {"Year": 2004, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 328519.989, "Electricity from fossil fuels (TWh)": 40.14, "Electricity from nuclear (TWh)": 11.6, "Electricity from renewables (TWh)": 329.43}, {"Year": 2005, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 331690.0024, "Electricity from fossil fuels (TWh)": 39.56, "Electricity from nuclear (TWh)": 9.2, "Electricity from renewables (TWh)": 346.96}, {"Year": 2006, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 335619.9951, "Electricity from fossil fuels (TWh)": 39.4, "Electricity from nuclear (TWh)": 12.98, "Electricity from renewables (TWh)": 359.55}, {"Year": 2007, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 352559.9976, "Electricity from fossil fuels (TWh)": 37.64, "Electricity from nuclear (TWh)": 11.65, "Electricity from renewables (TWh)": 387.88}, {"Year": 2008, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 373630.0049, "Electricity from fossil fuels (TWh)": 55.87, "Electricity from nuclear (TWh)": 13.21, "Electricity from renewables (TWh)": 385.61}, {"Year": 2009, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 350000, "Electricity from fossil fuels (TWh)": 36.32, "Electricity from nuclear (TWh)": 12.22, "Electricity from renewables (TWh)": 410.13}, {"Year": 2010, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 397929.9927, "Electricity from fossil fuels (TWh)": 61.02, "Electricity from nuclear (TWh)": 13.77, "Electricity from renewables (TWh)": 435.99}, {"Year": 2011, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 418309.9976, "Electricity from fossil fuels (TWh)": 50.27, "Electricity from nuclear (TWh)": 14.8, "Electricity from renewables (TWh)": 462.32}, {"Year": 2012, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 454230.011, "Electricity from fossil fuels (TWh)": 77.21, "Electricity from nuclear (TWh)": 15.17, "Electricity from renewables (TWh)": 454.78}, {"Year": 2013, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 486839.9963, "Electricity from fossil fuels (TWh)": 112, "Electricity from nuclear (TWh)": 14.65, "Electricity from renewables (TWh)": 436.84}, {"Year": 2014, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 511619.9951, "Electricity from fossil fuels (TWh)": 136.58, "Electricity from nuclear (TWh)": 14.46, "Electricity from renewables (TWh)": 430.82}, {"Year": 2015, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 485339.9963, "Electricity from fossil fuels (TWh)": 128.85, "Electricity from nuclear (TWh)": 13.91, "Electricity from renewables (TWh)": 428.81}, {"Year": 2016, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 447079.9866, "Electricity from fossil fuels (TWh)": 93.06, "Electricity from nuclear (TWh)": 14.97, "Electricity from renewables (TWh)": 463.37}, {"Year": 2017, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 456489.9902, "Electricity from fossil fuels (TWh)": 101.9, "Electricity from nuclear (TWh)": 14.86, "Electricity from renewables (TWh)": 464.4}, {"Year": 2018, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 433989.9902, "Electricity from fossil fuels (TWh)": 86.69, "Electricity from nuclear (TWh)": 14.79, "Electricity from renewables (TWh)": 492.66}, {"Year": 2019, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 434299.9878, "Electricity from fossil fuels (TWh)": 90.91, "Electricity from nuclear (TWh)": 15.16, "Electricity from renewables (TWh)": 512.59}, {"Year": 2020, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 81.15, "Electricity from nuclear (TWh)": 13.21, "Electricity from renewables (TWh)": 520.01}, {"Year": 2000, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 514220, "Electricity from fossil fuels (TWh)": 155.56, "Electricity from nuclear (TWh)": 69.16, "Electricity from renewables (TWh)": 363.7}, {"Year": 2001, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 506620, "Electricity from fossil fuels (TWh)": 159.93, "Electricity from nuclear (TWh)": 72.86, "Electricity from renewables (TWh)": 339.58}, {"Year": 2002, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 524349.9756, "Electricity from fossil fuels (TWh)": 155.12, "Electricity from nuclear (TWh)": 71.75, "Electricity from renewables (TWh)": 357.06}, {"Year": 2003, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 544539.978, "Electricity from fossil fuels (TWh)": 157.35, "Electricity from nuclear (TWh)": 71.15, "Electricity from renewables (TWh)": 343.88}, {"Year": 2004, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 536419.9829, "Electricity from fossil fuels (TWh)": 148.86, "Electricity from nuclear (TWh)": 85.87, "Electricity from renewables (TWh)": 347.68}, {"Year": 2005, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 549030.0293, "Electricity from fossil fuels (TWh)": 150.78, "Electricity from nuclear (TWh)": 86.83, "Electricity from renewables (TWh)": 368.86}, {"Year": 2006, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 540530.0293, "Electricity from fossil fuels (TWh)": 139.71, "Electricity from nuclear (TWh)": 92.44, "Electricity from renewables (TWh)": 360.48}, {"Year": 2007, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 571630.0049, "Electricity from fossil fuels (TWh)": 149.36, "Electricity from nuclear (TWh)": 88.19, "Electricity from renewables (TWh)": 375.42}, {"Year": 2008, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 550469.9707, "Electricity from fossil fuels (TWh)": 141.33, "Electricity from nuclear (TWh)": 88.3, "Electricity from renewables (TWh)": 385.21}, {"Year": 2009, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 521320.0073, "Electricity from fossil fuels (TWh)": 129.76, "Electricity from nuclear (TWh)": 85.13, "Electricity from renewables (TWh)": 380.24}, {"Year": 2010, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 537010.0098, "Electricity from fossil fuels (TWh)": 130.08, "Electricity from nuclear (TWh)": 85.53, "Electricity from renewables (TWh)": 366.21}, {"Year": 2011, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 549289.978, "Electricity from fossil fuels (TWh)": 131.3, "Electricity from nuclear (TWh)": 88.29, "Electricity from renewables (TWh)": 391.95}, {"Year": 2012, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 546210.022, "Electricity from fossil fuels (TWh)": 124.2, "Electricity from nuclear (TWh)": 89.49, "Electricity from renewables (TWh)": 398.58}, {"Year": 2013, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 555659.9731, "Electricity from fossil fuels (TWh)": 122.87, "Electricity from nuclear (TWh)": 97.58, "Electricity from renewables (TWh)": 417.28}, {"Year": 2014, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 561679.9927, "Electricity from fossil fuels (TWh)": 122.75, "Electricity from nuclear (TWh)": 101.21, "Electricity from renewables (TWh)": 412.13}, {"Year": 2015, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 558700.0122, "Electricity from fossil fuels (TWh)": 125.7, "Electricity from nuclear (TWh)": 96.05, "Electricity from renewables (TWh)": 417.2}, {"Year": 2016, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 556830.0171, "Electricity from fossil fuels (TWh)": 122.35, "Electricity from nuclear (TWh)": 95.69, "Electricity from renewables (TWh)": 426.84}, {"Year": 2017, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 568080.0171, "Electricity from fossil fuels (TWh)": 113.7, "Electricity from nuclear (TWh)": 95.57, "Electricity from renewables (TWh)": 435.43}, {"Year": 2018, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 580090.0269, "Electricity from fossil fuels (TWh)": 112.47, "Electricity from nuclear (TWh)": 95.03, "Electricity from renewables (TWh)": 428.39}, {"Year": 2019, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 580210.022, "Electricity from fossil fuels (TWh)": 110.65, "Electricity from nuclear (TWh)": 95.47, "Electricity from renewables (TWh)": 421.8}, {"Year": 2020, "Entity": "Canada", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 102.19, "Electricity from nuclear (TWh)": 92.65, "Electricity from renewables (TWh)": 429.24}, {"Year": 2000, "Entity": "China", "Value_co2_emissions_kt_by_country": 3346530, "Electricity from fossil fuels (TWh)": 1113.3, "Electricity from nuclear (TWh)": 16.74, "Electricity from renewables (TWh)": 225.56}, {"Year": 2001, "Entity": "China", "Value_co2_emissions_kt_by_country": 3529080, "Electricity from fossil fuels (TWh)": 1182.59, "Electricity from nuclear (TWh)": 17.47, "Electricity from renewables (TWh)": 280.73}, {"Year": 2002, "Entity": "China", "Value_co2_emissions_kt_by_country": 3810060.059, "Electricity from fossil fuels (TWh)": 1337.46, "Electricity from nuclear (TWh)": 25.13, "Electricity from renewables (TWh)": 291.41}, {"Year": 2003, "Entity": "China", "Value_co2_emissions_kt_by_country": 4415910.156, "Electricity from fossil fuels (TWh)": 1579.96, "Electricity from nuclear (TWh)": 43.34, "Electricity from renewables (TWh)": 287.28}, {"Year": 2004, "Entity": "China", "Value_co2_emissions_kt_by_country": 5124819.824, "Electricity from fossil fuels (TWh)": 1795.41, "Electricity from nuclear (TWh)": 50.47, "Electricity from renewables (TWh)": 357.43}, {"Year": 2005, "Entity": "China", "Value_co2_emissions_kt_by_country": 5824629.883, "Electricity from fossil fuels (TWh)": 2042.8, "Electricity from nuclear (TWh)": 53.09, "Electricity from renewables (TWh)": 404.37}, {"Year": 2006, "Entity": "China", "Value_co2_emissions_kt_by_country": 6437470.215, "Electricity from fossil fuels (TWh)": 2364.16, "Electricity from nuclear (TWh)": 54.84, "Electricity from renewables (TWh)": 446.72}, {"Year": 2007, "Entity": "China", "Value_co2_emissions_kt_by_country": 6993180.176, "Electricity from fossil fuels (TWh)": 2718.7, "Electricity from nuclear (TWh)": 62.13, "Electricity from renewables (TWh)": 500.71}, {"Year": 2008, "Entity": "China", "Value_co2_emissions_kt_by_country": 7199600.098, "Electricity from fossil fuels (TWh)": 2762.29, "Electricity from nuclear (TWh)": 68.39, "Electricity from renewables (TWh)": 665.08}, {"Year": 2009, "Entity": "China", "Value_co2_emissions_kt_by_country": 7719069.824, "Electricity from fossil fuels (TWh)": 2980.2, "Electricity from nuclear (TWh)": 70.05, "Electricity from renewables (TWh)": 664.39}, {"Year": 2010, "Entity": "China", "Value_co2_emissions_kt_by_country": 8474919.922, "Electricity from fossil fuels (TWh)": 3326.19, "Electricity from nuclear (TWh)": 74.74, "Electricity from renewables (TWh)": 786.38}, {"Year": 2011, "Entity": "China", "Value_co2_emissions_kt_by_country": 9282549.805, "Electricity from fossil fuels (TWh)": 3811.77, "Electricity from nuclear (TWh)": 87.2, "Electricity from renewables (TWh)": 792.38}, {"Year": 2012, "Entity": "China", "Value_co2_emissions_kt_by_country": 9541870.117, "Electricity from fossil fuels (TWh)": 3869.38, "Electricity from nuclear (TWh)": 98.32, "Electricity from renewables (TWh)": 999.56}, {"Year": 2013, "Entity": "China", "Value_co2_emissions_kt_by_country": 9984570.313, "Electricity from fossil fuels (TWh)": 4203.77, "Electricity from nuclear (TWh)": 111.5, "Electricity from renewables (TWh)": 1093.37}, {"Year": 2014, "Entity": "China", "Value_co2_emissions_kt_by_country": 10006669.92, "Electricity from fossil fuels (TWh)": 4345.86, "Electricity from nuclear (TWh)": 133.22, "Electricity from renewables (TWh)": 1289.23}, {"Year": 2015, "Entity": "China", "Value_co2_emissions_kt_by_country": 9861099.609, "Electricity from fossil fuels (TWh)": 4222.76, "Electricity from nuclear (TWh)": 171.38, "Electricity from renewables (TWh)": 1393.66}, {"Year": 2016, "Entity": "China", "Value_co2_emissions_kt_by_country": 9874660.156, "Electricity from fossil fuels (TWh)": 4355, "Electricity from nuclear (TWh)": 213.18, "Electricity from renewables (TWh)": 1522.79}, {"Year": 2017, "Entity": "China", "Value_co2_emissions_kt_by_country": 10096009.77, "Electricity from fossil fuels (TWh)": 4643.1, "Electricity from nuclear (TWh)": 248.1, "Electricity from renewables (TWh)": 1667.06}, {"Year": 2018, "Entity": "China", "Value_co2_emissions_kt_by_country": 10502929.69, "Electricity from fossil fuels (TWh)": 4990.28, "Electricity from nuclear (TWh)": 295, "Electricity from renewables (TWh)": 1835.32}, {"Year": 2019, "Entity": "China", "Value_co2_emissions_kt_by_country": 10707219.73, "Electricity from fossil fuels (TWh)": 5098.22, "Electricity from nuclear (TWh)": 348.7, "Electricity from renewables (TWh)": 2014.57}, {"Year": 2020, "Entity": "China", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 5184.13, "Electricity from nuclear (TWh)": 366.2, "Electricity from renewables (TWh)": 2184.94}, {"Year": 2000, "Entity": "France", "Value_co2_emissions_kt_by_country": 373120, "Electricity from fossil fuels (TWh)": 50.61, "Electricity from nuclear (TWh)": 415.16, "Electricity from renewables (TWh)": 67.83}, {"Year": 2001, "Entity": "France", "Value_co2_emissions_kt_by_country": 376730, "Electricity from fossil fuels (TWh)": 46.48, "Electricity from nuclear (TWh)": 421.08, "Electricity from renewables (TWh)": 76.09}, {"Year": 2002, "Entity": "France", "Value_co2_emissions_kt_by_country": 371019.989, "Electricity from fossil fuels (TWh)": 52.67, "Electricity from nuclear (TWh)": 436.76, "Electricity from renewables (TWh)": 62.69}, {"Year": 2003, "Entity": "France", "Value_co2_emissions_kt_by_country": 376709.9915, "Electricity from fossil fuels (TWh)": 57.38, "Electricity from nuclear (TWh)": 441.07, "Electricity from renewables (TWh)": 61.47}, {"Year": 2004, "Entity": "France", "Value_co2_emissions_kt_by_country": 377790.0085, "Electricity from fossil fuels (TWh)": 56.53, "Electricity from nuclear (TWh)": 448.24, "Electricity from renewables (TWh)": 62.42}, {"Year": 2005, "Entity": "France", "Value_co2_emissions_kt_by_country": 380660.0037, "Electricity from fossil fuels (TWh)": 63.35, "Electricity from nuclear (TWh)": 451.53, "Electricity from renewables (TWh)": 54.98}, {"Year": 2006, "Entity": "France", "Value_co2_emissions_kt_by_country": 371549.9878, "Electricity from fossil fuels (TWh)": 56.9, "Electricity from nuclear (TWh)": 450.19, "Electricity from renewables (TWh)": 60.91}, {"Year": 2007, "Entity": "France", "Value_co2_emissions_kt_by_country": 362829.9866, "Electricity from fossil fuels (TWh)": 58.18, "Electricity from nuclear (TWh)": 439.73, "Electricity from renewables (TWh)": 64.3}, {"Year": 2008, "Entity": "France", "Value_co2_emissions_kt_by_country": 357989.9902, "Electricity from fossil fuels (TWh)": 55.57, "Electricity from nuclear (TWh)": 439.45, "Electricity from renewables (TWh)": 72.33}, {"Year": 2009, "Entity": "France", "Value_co2_emissions_kt_by_country": 343730.011, "Electricity from fossil fuels (TWh)": 51.32, "Electricity from nuclear (TWh)": 409.74, "Electricity from renewables (TWh)": 68.15}, {"Year": 2010, "Entity": "France", "Value_co2_emissions_kt_by_country": 347779.9988, "Electricity from fossil fuels (TWh)": 57.63, "Electricity from nuclear (TWh)": 428.52, "Electricity from renewables (TWh)": 76.68}, {"Year": 2011, "Entity": "France", "Value_co2_emissions_kt_by_country": 335140.0146, "Electricity from fossil fuels (TWh)": 58.99, "Electricity from nuclear (TWh)": 442.39, "Electricity from renewables (TWh)": 66.02}, {"Year": 2012, "Entity": "France", "Value_co2_emissions_kt_by_country": 338420.0134, "Electricity from fossil fuels (TWh)": 56.42, "Electricity from nuclear (TWh)": 425.41, "Electricity from renewables (TWh)": 85.25}, {"Year": 2013, "Entity": "France", "Value_co2_emissions_kt_by_country": 338559.9976, "Electricity from fossil fuels (TWh)": 53.35, "Electricity from nuclear (TWh)": 423.68, "Electricity from renewables (TWh)": 99.42}, {"Year": 2014, "Entity": "France", "Value_co2_emissions_kt_by_country": 306100.0061, "Electricity from fossil fuels (TWh)": 35.68, "Electricity from nuclear (TWh)": 436.48, "Electricity from renewables (TWh)": 94.03}, {"Year": 2015, "Entity": "France", "Value_co2_emissions_kt_by_country": 311299.9878, "Electricity from fossil fuels (TWh)": 44.65, "Electricity from nuclear (TWh)": 437.43, "Electricity from renewables (TWh)": 91.84}, {"Year": 2016, "Entity": "France", "Value_co2_emissions_kt_by_country": 313920.0134, "Electricity from fossil fuels (TWh)": 56.45, "Electricity from nuclear (TWh)": 403.2, "Electricity from renewables (TWh)": 99}, {"Year": 2017, "Entity": "France", "Value_co2_emissions_kt_by_country": 317829.9866, "Electricity from fossil fuels (TWh)": 65.09, "Electricity from nuclear (TWh)": 398.36, "Electricity from renewables (TWh)": 92.63}, {"Year": 2018, "Entity": "France", "Value_co2_emissions_kt_by_country": 307049.9878, "Electricity from fossil fuels (TWh)": 49.27, "Electricity from nuclear (TWh)": 412.94, "Electricity from renewables (TWh)": 113.62}, {"Year": 2019, "Entity": "France", "Value_co2_emissions_kt_by_country": 300519.989, "Electricity from fossil fuels (TWh)": 53.5, "Electricity from nuclear (TWh)": 399.01, "Electricity from renewables (TWh)": 113.21}, {"Year": 2020, "Entity": "France", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 48.14, "Electricity from nuclear (TWh)": 353.83, "Electricity from renewables (TWh)": 125.28}, {"Year": 2000, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 830280, "Electricity from fossil fuels (TWh)": 367.22, "Electricity from nuclear (TWh)": 169.61, "Electricity from renewables (TWh)": 35.47}, {"Year": 2001, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 847680, "Electricity from fossil fuels (TWh)": 372.69, "Electricity from nuclear (TWh)": 171.3, "Electricity from renewables (TWh)": 37.9}, {"Year": 2002, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 833380.0049, "Electricity from fossil fuels (TWh)": 372.64, "Electricity from nuclear (TWh)": 164.84, "Electricity from renewables (TWh)": 44.48}, {"Year": 2003, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 836789.978, "Electricity from fossil fuels (TWh)": 390.81, "Electricity from nuclear (TWh)": 165.06, "Electricity from renewables (TWh)": 46.67}, {"Year": 2004, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 821070.0073, "Electricity from fossil fuels (TWh)": 385.24, "Electricity from nuclear (TWh)": 167.07, "Electricity from renewables (TWh)": 57.97}, {"Year": 2005, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 802380.0049, "Electricity from fossil fuels (TWh)": 386.96, "Electricity from nuclear (TWh)": 163.05, "Electricity from renewables (TWh)": 63.4}, {"Year": 2006, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 814409.9731, "Electricity from fossil fuels (TWh)": 390.03, "Electricity from nuclear (TWh)": 167.27, "Electricity from renewables (TWh)": 72.51}, {"Year": 2007, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 783799.9878, "Electricity from fossil fuels (TWh)": 402.4, "Electricity from nuclear (TWh)": 140.53, "Electricity from renewables (TWh)": 89.38}, {"Year": 2008, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 789690.0024, "Electricity from fossil fuels (TWh)": 390.43, "Electricity from nuclear (TWh)": 148.49, "Electricity from renewables (TWh)": 94.28}, {"Year": 2009, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 734809.9976, "Electricity from fossil fuels (TWh)": 358.07, "Electricity from nuclear (TWh)": 134.93, "Electricity from renewables (TWh)": 95.94}, {"Year": 2010, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 773070.0073, "Electricity from fossil fuels (TWh)": 378.9, "Electricity from nuclear (TWh)": 140.56, "Electricity from renewables (TWh)": 105.18}, {"Year": 2011, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 746479.9805, "Electricity from fossil fuels (TWh)": 373.16, "Electricity from nuclear (TWh)": 107.97, "Electricity from renewables (TWh)": 124.04}, {"Year": 2012, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 760130.0049, "Electricity from fossil fuels (TWh)": 377.89, "Electricity from nuclear (TWh)": 99.46, "Electricity from renewables (TWh)": 143.04}, {"Year": 2013, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 776150.0244, "Electricity from fossil fuels (TWh)": 381.52, "Electricity from nuclear (TWh)": 97.29, "Electricity from renewables (TWh)": 152.34}, {"Year": 2014, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 736010.0098, "Electricity from fossil fuels (TWh)": 360.28, "Electricity from nuclear (TWh)": 97.13, "Electricity from renewables (TWh)": 162.54}, {"Year": 2015, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 742309.9976, "Electricity from fossil fuels (TWh)": 359.99, "Electricity from nuclear (TWh)": 91.79, "Electricity from renewables (TWh)": 188.79}, {"Year": 2016, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 747150.0244, "Electricity from fossil fuels (TWh)": 368.67, "Electricity from nuclear (TWh)": 84.63, "Electricity from renewables (TWh)": 189.67}, {"Year": 2017, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 732200.0122, "Electricity from fossil fuels (TWh)": 353.37, "Electricity from nuclear (TWh)": 76.32, "Electricity from renewables (TWh)": 216.32}, {"Year": 2018, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 707700.0122, "Electricity from fossil fuels (TWh)": 334.65, "Electricity from nuclear (TWh)": 76, "Electricity from renewables (TWh)": 222.07}, {"Year": 2019, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 657400.0244, "Electricity from fossil fuels (TWh)": 284.09, "Electricity from nuclear (TWh)": 75.07, "Electricity from renewables (TWh)": 240.33}, {"Year": 2020, "Entity": "Germany", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 251.4, "Electricity from nuclear (TWh)": 64.38, "Electricity from renewables (TWh)": 251.48}, {"Year": 2000, "Entity": "India", "Value_co2_emissions_kt_by_country": 937860, "Electricity from fossil fuels (TWh)": 475.35, "Electricity from nuclear (TWh)": 15.77, "Electricity from renewables (TWh)": 80.27}, {"Year": 2001, "Entity": "India", "Value_co2_emissions_kt_by_country": 953540, "Electricity from fossil fuels (TWh)": 491.01, "Electricity from nuclear (TWh)": 18.89, "Electricity from renewables (TWh)": 76.19}, {"Year": 2002, "Entity": "India", "Value_co2_emissions_kt_by_country": 985450.0122, "Electricity from fossil fuels (TWh)": 517.51, "Electricity from nuclear (TWh)": 19.35, "Electricity from renewables (TWh)": 72.78}, {"Year": 2003, "Entity": "India", "Value_co2_emissions_kt_by_country": 1011770.02, "Electricity from fossil fuels (TWh)": 545.36, "Electricity from nuclear (TWh)": 18.14, "Electricity from renewables (TWh)": 74.63}, {"Year": 2004, "Entity": "India", "Value_co2_emissions_kt_by_country": 1085670.044, "Electricity from fossil fuels (TWh)": 567.86, "Electricity from nuclear (TWh)": 21.26, "Electricity from renewables (TWh)": 109.2}, {"Year": 2005, "Entity": "India", "Value_co2_emissions_kt_by_country": 1136469.971, "Electricity from fossil fuels (TWh)": 579.32, "Electricity from nuclear (TWh)": 17.73, "Electricity from renewables (TWh)": 107.47}, {"Year": 2006, "Entity": "India", "Value_co2_emissions_kt_by_country": 1215209.961, "Electricity from fossil fuels (TWh)": 599.24, "Electricity from nuclear (TWh)": 17.63, "Electricity from renewables (TWh)": 127.56}, {"Year": 2007, "Entity": "India", "Value_co2_emissions_kt_by_country": 1336739.99, "Electricity from fossil fuels (TWh)": 636.68, "Electricity from nuclear (TWh)": 17.83, "Electricity from renewables (TWh)": 141.75}, {"Year": 2008, "Entity": "India", "Value_co2_emissions_kt_by_country": 1424380.005, "Electricity from fossil fuels (TWh)": 674.27, "Electricity from nuclear (TWh)": 15.23, "Electricity from renewables (TWh)": 138.91}, {"Year": 2009, "Entity": "India", "Value_co2_emissions_kt_by_country": 1564880.005, "Electricity from fossil fuels (TWh)": 728.56, "Electricity from nuclear (TWh)": 16.82, "Electricity from renewables (TWh)": 134.33}, {"Year": 2010, "Entity": "India", "Value_co2_emissions_kt_by_country": 1659979.98, "Electricity from fossil fuels (TWh)": 771.78, "Electricity from nuclear (TWh)": 23.08, "Electricity from renewables (TWh)": 142.61}, {"Year": 2011, "Entity": "India", "Value_co2_emissions_kt_by_country": 1756739.99, "Electricity from fossil fuels (TWh)": 828.16, "Electricity from nuclear (TWh)": 32.22, "Electricity from renewables (TWh)": 173.62}, {"Year": 2012, "Entity": "India", "Value_co2_emissions_kt_by_country": 1909439.941, "Electricity from fossil fuels (TWh)": 893.45, "Electricity from nuclear (TWh)": 33.14, "Electricity from renewables (TWh)": 165.25}, {"Year": 2013, "Entity": "India", "Value_co2_emissions_kt_by_country": 1972430.054, "Electricity from fossil fuels (TWh)": 924.93, "Electricity from nuclear (TWh)": 33.31, "Electricity from renewables (TWh)": 187.9}, {"Year": 2014, "Entity": "India", "Value_co2_emissions_kt_by_country": 2147110.107, "Electricity from fossil fuels (TWh)": 1025.29, "Electricity from nuclear (TWh)": 34.69, "Electricity from renewables (TWh)": 202.04}, {"Year": 2015, "Entity": "India", "Value_co2_emissions_kt_by_country": 2158020.02, "Electricity from fossil fuels (TWh)": 1080.44, "Electricity from nuclear (TWh)": 38.31, "Electricity from renewables (TWh)": 203.21}, {"Year": 2016, "Entity": "India", "Value_co2_emissions_kt_by_country": 2195250, "Electricity from fossil fuels (TWh)": 1155.52, "Electricity from nuclear (TWh)": 37.9, "Electricity from renewables (TWh)": 208.21}, {"Year": 2017, "Entity": "India", "Value_co2_emissions_kt_by_country": 2320409.912, "Electricity from fossil fuels (TWh)": 1198.85, "Electricity from nuclear (TWh)": 37.41, "Electricity from renewables (TWh)": 234.9}, {"Year": 2018, "Entity": "India", "Value_co2_emissions_kt_by_country": 2451929.932, "Electricity from fossil fuels (TWh)": 1276.32, "Electricity from nuclear (TWh)": 39.05, "Electricity from renewables (TWh)": 263.61}, {"Year": 2019, "Entity": "India", "Value_co2_emissions_kt_by_country": 2456300.049, "Electricity from fossil fuels (TWh)": 1273.59, "Electricity from nuclear (TWh)": 45.16, "Electricity from renewables (TWh)": 303.16}, {"Year": 2020, "Entity": "India", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 1202.34, "Electricity from nuclear (TWh)": 44.61, "Electricity from renewables (TWh)": 315.76}, {"Year": 2000, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 280650, "Electricity from fossil fuels (TWh)": 78.43, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 19.6}, {"Year": 2001, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 302060, "Electricity from fossil fuels (TWh)": 83.96, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 22.19}, {"Year": 2002, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 305640.0146, "Electricity from fossil fuels (TWh)": 92.03, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 21}, {"Year": 2003, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 333890.0146, "Electricity from fossil fuels (TWh)": 97.57, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 19.82}, {"Year": 2004, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 341239.9902, "Electricity from fossil fuels (TWh)": 103.8, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 20.97}, {"Year": 2005, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 342149.9939, "Electricity from fossil fuels (TWh)": 110.22, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 22.66}, {"Year": 2006, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 364470.0012, "Electricity from fossil fuels (TWh)": 116.8, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 21.18}, {"Year": 2007, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 379959.9915, "Electricity from fossil fuels (TWh)": 124.1, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 24.29}, {"Year": 2008, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 376140.0146, "Electricity from fossil fuels (TWh)": 129.55, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 26.34}, {"Year": 2009, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 391079.9866, "Electricity from fossil fuels (TWh)": 136.05, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 26.79}, {"Year": 2010, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 415519.989, "Electricity from fossil fuels (TWh)": 142.88, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 34.63}, {"Year": 2011, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 475309.9976, "Electricity from fossil fuels (TWh)": 161.41, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 30.46}, {"Year": 2012, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 481510.0098, "Electricity from fossil fuels (TWh)": 177.83, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 31.11}, {"Year": 2013, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 447940.0024, "Electricity from fossil fuels (TWh)": 189.66, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 35.5}, {"Year": 2014, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 483910.0037, "Electricity from fossil fuels (TWh)": 203.11, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 34.41}, {"Year": 2015, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 488549.9878, "Electricity from fossil fuels (TWh)": 209.71, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 33.56}, {"Year": 2016, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 482510.0098, "Electricity from fossil fuels (TWh)": 217.97, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 39.58}, {"Year": 2017, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 517320.0073, "Electricity from fossil fuels (TWh)": 222.64, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 43.17}, {"Year": 2018, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 576989.9902, "Electricity from fossil fuels (TWh)": 235.41, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 48.38}, {"Year": 2019, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 619840.0269, "Electricity from fossil fuels (TWh)": 247.39, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 48.04}, {"Year": 2020, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 238.91, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 52.91}, {"Year": 2000, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 436300, "Electricity from fossil fuels (TWh)": 218.28, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 50.87}, {"Year": 2001, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 436570, "Electricity from fossil fuels (TWh)": 216.73, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 54.35}, {"Year": 2002, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 443470.0012, "Electricity from fossil fuels (TWh)": 228.45, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 48.31}, {"Year": 2003, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 462200.0122, "Electricity from fossil fuels (TWh)": 238.52, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 46.86}, {"Year": 2004, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 472399.9939, "Electricity from fossil fuels (TWh)": 240.95, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 53.88}, {"Year": 2005, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 473829.9866, "Electricity from fossil fuels (TWh)": 247.29, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 48.43}, {"Year": 2006, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 466649.9939, "Electricity from fossil fuels (TWh)": 256.03, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 50.64}, {"Year": 2007, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 459369.9951, "Electricity from fossil fuels (TWh)": 259.49, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 47.72}, {"Year": 2008, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 444980.011, "Electricity from fossil fuels (TWh)": 254.34, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 58.16}, {"Year": 2009, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 397059.9976, "Electricity from fossil fuels (TWh)": 218.32, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 69.26}, {"Year": 2010, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 405269.989, "Electricity from fossil fuels (TWh)": 220.93, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 76.98}, {"Year": 2011, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 396690.0024, "Electricity from fossil fuels (TWh)": 216.78, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 82.96}, {"Year": 2012, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 376750, "Electricity from fossil fuels (TWh)": 204.26, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 92.22}, {"Year": 2013, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 346459.9915, "Electricity from fossil fuels (TWh)": 175.07, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 112}, {"Year": 2014, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 327500, "Electricity from fossil fuels (TWh)": 156.76, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 120.68}, {"Year": 2015, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 337859.9854, "Electricity from fossil fuels (TWh)": 172.06, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 108.89}, {"Year": 2016, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 333339.9963, "Electricity from fossil fuels (TWh)": 179.19, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 108.01}, {"Year": 2017, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 329190.0024, "Electricity from fossil fuels (TWh)": 189.44, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 103.89}, {"Year": 2018, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 324880.0049, "Electricity from fossil fuels (TWh)": 172.98, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 114.41}, {"Year": 2019, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 317239.9902, "Electricity from fossil fuels (TWh)": 175.52, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 115.83}, {"Year": 2020, "Entity": "Italy", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 161.17, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 116.9}, {"Year": 2000, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1182610, "Electricity from fossil fuels (TWh)": 578.29, "Electricity from nuclear (TWh)": 305.95, "Electricity from renewables (TWh)": 104.16}, {"Year": 2001, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1170380, "Electricity from fossil fuels (TWh)": 564.95, "Electricity from nuclear (TWh)": 303.86, "Electricity from renewables (TWh)": 101.36}, {"Year": 2002, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1206599.976, "Electricity from fossil fuels (TWh)": 605.12, "Electricity from nuclear (TWh)": 280.34, "Electricity from renewables (TWh)": 101.1}, {"Year": 2003, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1214949.951, "Electricity from fossil fuels (TWh)": 633.76, "Electricity from nuclear (TWh)": 228.01, "Electricity from renewables (TWh)": 114.18}, {"Year": 2004, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1209849.976, "Electricity from fossil fuels (TWh)": 621.6, "Electricity from nuclear (TWh)": 268.32, "Electricity from renewables (TWh)": 114.73}, {"Year": 2005, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1212819.946, "Electricity from fossil fuels (TWh)": 634.09, "Electricity from nuclear (TWh)": 280.5, "Electricity from renewables (TWh)": 100.57}, {"Year": 2006, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1189520.02, "Electricity from fossil fuels (TWh)": 628.77, "Electricity from nuclear (TWh)": 291.54, "Electricity from renewables (TWh)": 112.07}, {"Year": 2007, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1225069.946, "Electricity from fossil fuels (TWh)": 705.37, "Electricity from nuclear (TWh)": 267.34, "Electricity from renewables (TWh)": 100.8}, {"Year": 2008, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1158219.971, "Electricity from fossil fuels (TWh)": 663.88, "Electricity from nuclear (TWh)": 241.25, "Electricity from renewables (TWh)": 100.79}, {"Year": 2009, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1100979.98, "Electricity from fossil fuels (TWh)": 611.86, "Electricity from nuclear (TWh)": 263.05, "Electricity from renewables (TWh)": 102.28}, {"Year": 2010, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1156479.98, "Electricity from fossil fuels (TWh)": 689.89, "Electricity from nuclear (TWh)": 278.36, "Electricity from renewables (TWh)": 113.92}, {"Year": 2011, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1213520.02, "Electricity from fossil fuels (TWh)": 777.1, "Electricity from nuclear (TWh)": 153.38, "Electricity from renewables (TWh)": 116.5}, {"Year": 2012, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1253609.985, "Electricity from fossil fuels (TWh)": 920.39, "Electricity from nuclear (TWh)": 15.12, "Electricity from renewables (TWh)": 111.09}, {"Year": 2013, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1262780.029, "Electricity from fossil fuels (TWh)": 897.88, "Electricity from nuclear (TWh)": 10.43, "Electricity from renewables (TWh)": 121.48}, {"Year": 2014, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1217119.995, "Electricity from fossil fuels (TWh)": 892.18, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 136.53}, {"Year": 2015, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1179439.941, "Electricity from fossil fuels (TWh)": 844.23, "Electricity from nuclear (TWh)": 3.24, "Electricity from renewables (TWh)": 157.34}, {"Year": 2016, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1167790.039, "Electricity from fossil fuels (TWh)": 832.4, "Electricity from nuclear (TWh)": 14.87, "Electricity from renewables (TWh)": 157.7}, {"Year": 2017, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1155229.98, "Electricity from fossil fuels (TWh)": 806.12, "Electricity from nuclear (TWh)": 27.75, "Electricity from renewables (TWh)": 175.12}, {"Year": 2018, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1116150.024, "Electricity from fossil fuels (TWh)": 780.61, "Electricity from nuclear (TWh)": 47.82, "Electricity from renewables (TWh)": 183.63}, {"Year": 2019, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1081569.946, "Electricity from fossil fuels (TWh)": 735.66, "Electricity from nuclear (TWh)": 63.88, "Electricity from renewables (TWh)": 192.72}, {"Year": 2020, "Entity": "Japan", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 716.67, "Electricity from nuclear (TWh)": 41.86, "Electricity from renewables (TWh)": 205.6}, {"Year": 2000, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 120150, "Electricity from fossil fuels (TWh)": 44.11, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.53}, {"Year": 2001, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 117440, "Electricity from fossil fuels (TWh)": 47.3, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.08}, {"Year": 2002, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 131059.9976, "Electricity from fossil fuels (TWh)": 49.44, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.89}, {"Year": 2003, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 146139.9994, "Electricity from fossil fuels (TWh)": 55.24, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.62}, {"Year": 2004, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 158029.9988, "Electricity from fossil fuels (TWh)": 58.89, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.06}, {"Year": 2005, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 169210.0067, "Electricity from fossil fuels (TWh)": 60.06, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.86}, {"Year": 2006, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 185300.0031, "Electricity from fossil fuels (TWh)": 63.89, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.77}, {"Year": 2007, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 198389.9994, "Electricity from fossil fuels (TWh)": 68.45, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.17}, {"Year": 2008, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 242029.9988, "Electricity from fossil fuels (TWh)": 72.89, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.46}, {"Year": 2009, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 213610.0006, "Electricity from fossil fuels (TWh)": 71.85, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 6.88}, {"Year": 2010, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 229699.9969, "Electricity from fossil fuels (TWh)": 74.63, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.02}, {"Year": 2011, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 245449.9969, "Electricity from fossil fuels (TWh)": 78.7, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.88}, {"Year": 2012, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 244600.0061, "Electricity from fossil fuels (TWh)": 82.98, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.64}, {"Year": 2013, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 260010.0098, "Electricity from fossil fuels (TWh)": 84.88, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.73}, {"Year": 2014, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 209229.9957, "Electricity from fossil fuels (TWh)": 86.37, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.27}, {"Year": 2015, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 190729.9957, "Electricity from fossil fuels (TWh)": 82.2, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 9.45}, {"Year": 2016, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 202149.9939, "Electricity from fossil fuels (TWh)": 82.65, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 11.98}, {"Year": 2017, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 214580.0018, "Electricity from fossil fuels (TWh)": 91.48, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 11.64}, {"Year": 2018, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 216600.0061, "Electricity from fossil fuels (TWh)": 96.36, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 10.91}, {"Year": 2019, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 212110.0006, "Electricity from fossil fuels (TWh)": 95.39, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 11.09}, {"Year": 2020, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 96.7, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 11.94}, {"Year": 2000, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 379180, "Electricity from fossil fuels (TWh)": 141.8, "Electricity from nuclear (TWh)": 7.81, "Electricity from renewables (TWh)": 44.51}, {"Year": 2001, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 378830, "Electricity from fossil fuels (TWh)": 153.32, "Electricity from nuclear (TWh)": 8.29, "Electricity from renewables (TWh)": 39.56}, {"Year": 2002, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 386000, "Electricity from fossil fuels (TWh)": 159.81, "Electricity from nuclear (TWh)": 9.26, "Electricity from renewables (TWh)": 35.67}, {"Year": 2003, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 404690.0024, "Electricity from fossil fuels (TWh)": 160.45, "Electricity from nuclear (TWh)": 9.98, "Electricity from renewables (TWh)": 32.11}, {"Year": 2004, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 414100.0061, "Electricity from fossil fuels (TWh)": 173.66, "Electricity from nuclear (TWh)": 8.73, "Electricity from renewables (TWh)": 38.19}, {"Year": 2005, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 432190.0024, "Electricity from fossil fuels (TWh)": 178.76, "Electricity from nuclear (TWh)": 10.32, "Electricity from renewables (TWh)": 42.29}, {"Year": 2006, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 448299.9878, "Electricity from fossil fuels (TWh)": 182.76, "Electricity from nuclear (TWh)": 10.4, "Electricity from renewables (TWh)": 43.63}, {"Year": 2007, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 457119.9951, "Electricity from fossil fuels (TWh)": 191.83, "Electricity from nuclear (TWh)": 9.95, "Electricity from renewables (TWh)": 42.14}, {"Year": 2008, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 459549.9878, "Electricity from fossil fuels (TWh)": 184.51, "Electricity from nuclear (TWh)": 9.36, "Electricity from renewables (TWh)": 53.22}, {"Year": 2009, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 448369.9951, "Electricity from fossil fuels (TWh)": 194.75, "Electricity from nuclear (TWh)": 10.11, "Electricity from renewables (TWh)": 40.59}, {"Year": 2010, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 462869.9951, "Electricity from fossil fuels (TWh)": 207.38, "Electricity from nuclear (TWh)": 5.66, "Electricity from renewables (TWh)": 51.37}, {"Year": 2011, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 478399.9939, "Electricity from fossil fuels (TWh)": 219.88, "Electricity from nuclear (TWh)": 9.66, "Electricity from renewables (TWh)": 50.7}, {"Year": 2012, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 486450.0122, "Electricity from fossil fuels (TWh)": 229.14, "Electricity from nuclear (TWh)": 8.41, "Electricity from renewables (TWh)": 47.2}, {"Year": 2013, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 475739.9902, "Electricity from fossil fuels (TWh)": 231.23, "Electricity from nuclear (TWh)": 11.38, "Electricity from renewables (TWh)": 44.67}, {"Year": 2014, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 462239.9902, "Electricity from fossil fuels (TWh)": 223.43, "Electricity from nuclear (TWh)": 9.3, "Electricity from renewables (TWh)": 57.46}, {"Year": 2015, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 471630.0049, "Electricity from fossil fuels (TWh)": 234.28, "Electricity from nuclear (TWh)": 11.18, "Electricity from renewables (TWh)": 52.42}, {"Year": 2016, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 473309.9976, "Electricity from fossil fuels (TWh)": 239.78, "Electricity from nuclear (TWh)": 10.27, "Electricity from renewables (TWh)": 52.97}, {"Year": 2017, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 471579.9866, "Electricity from fossil fuels (TWh)": 242.69, "Electricity from nuclear (TWh)": 10.57, "Electricity from renewables (TWh)": 55.88}, {"Year": 2018, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 452570.0073, "Electricity from fossil fuels (TWh)": 259.92, "Electricity from nuclear (TWh)": 13.32, "Electricity from renewables (TWh)": 58.78}, {"Year": 2019, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 449269.989, "Electricity from fossil fuels (TWh)": 248.2, "Electricity from nuclear (TWh)": 10.88, "Electricity from renewables (TWh)": 59}, {"Year": 2020, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 245.46, "Electricity from nuclear (TWh)": 10.87, "Electricity from renewables (TWh)": 69.19}, {"Year": 2000, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 295770, "Electricity from fossil fuels (TWh)": 140.85, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 2.33}, {"Year": 2001, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 293630, "Electricity from fossil fuels (TWh)": 140.94, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 2.78}, {"Year": 2002, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 287320.0073, "Electricity from fossil fuels (TWh)": 139.72, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 2.77}, {"Year": 2003, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 297730.011, "Electricity from fossil fuels (TWh)": 147.76, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 2.25}, {"Year": 2004, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 301850.0061, "Electricity from fossil fuels (TWh)": 149.06, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 3.2}, {"Year": 2005, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 301350.0061, "Electricity from fossil fuels (TWh)": 151.2, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 3.85}, {"Year": 2006, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 314089.9963, "Electricity from fossil fuels (TWh)": 156.16, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 4.29}, {"Year": 2007, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 313380.0049, "Electricity from fossil fuels (TWh)": 153.08, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 5.43}, {"Year": 2008, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 308329.9866, "Electricity from fossil fuels (TWh)": 148.03, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 6.61}, {"Year": 2009, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 297260.0098, "Electricity from fossil fuels (TWh)": 142.4, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.69}, {"Year": 2010, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 313739.9902, "Electricity from fossil fuels (TWh)": 146.12, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 10.88}, {"Year": 2011, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 310589.9963, "Electricity from fossil fuels (TWh)": 149.88, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 13.13}, {"Year": 2012, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 303350.0061, "Electricity from fossil fuels (TWh)": 144.75, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 16.88}, {"Year": 2013, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 298299.9878, "Electricity from fossil fuels (TWh)": 146.85, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 17.06}, {"Year": 2014, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 285730.011, "Electricity from fossil fuels (TWh)": 138.53, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 19.85}, {"Year": 2015, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 289079.9866, "Electricity from fossil fuels (TWh)": 141.55, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 22.69}, {"Year": 2016, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 299799.9878, "Electricity from fossil fuels (TWh)": 143.28, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 22.81}, {"Year": 2017, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 312859.9854, "Electricity from fossil fuels (TWh)": 145.8, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 24.13}, {"Year": 2018, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 311910.0037, "Electricity from fossil fuels (TWh)": 147.87, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 21.62}, {"Year": 2019, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 295130.0049, "Electricity from fossil fuels (TWh)": 137.58, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 25.46}, {"Year": 2020, "Entity": "Poland", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 128.91, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 28.23}, {"Year": 2000, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 249660, "Electricity from fossil fuels (TWh)": 138.68, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2001, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 254090, "Electricity from fossil fuels (TWh)": 146.09, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2002, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 272250, "Electricity from fossil fuels (TWh)": 154.91, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2003, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 284829.9866, "Electricity from fossil fuels (TWh)": 166.58, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2004, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 299890.0146, "Electricity from fossil fuels (TWh)": 173.41, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2005, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 315290.0085, "Electricity from fossil fuels (TWh)": 191.05, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2006, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 335440.0024, "Electricity from fossil fuels (TWh)": 196.31, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2007, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 354619.9951, "Electricity from fossil fuels (TWh)": 204.43, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2008, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 389720.0012, "Electricity from fossil fuels (TWh)": 204.2, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2009, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 406529.9988, "Electricity from fossil fuels (TWh)": 217.31, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2010, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 446130.0049, "Electricity from fossil fuels (TWh)": 240.06, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2011, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 463769.989, "Electricity from fossil fuels (TWh)": 250.07, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.01}, {"Year": 2012, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 492470.0012, "Electricity from fossil fuels (TWh)": 271.68, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.03}, {"Year": 2013, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 503209.9915, "Electricity from fossil fuels (TWh)": 284.02, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.04}, {"Year": 2014, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 540520.0195, "Electricity from fossil fuels (TWh)": 311.81, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.05}, {"Year": 2015, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 565190.0024, "Electricity from fossil fuels (TWh)": 338.34, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.05}, {"Year": 2016, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 561229.9805, "Electricity from fossil fuels (TWh)": 337.38, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.05}, {"Year": 2017, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 545070.0073, "Electricity from fossil fuels (TWh)": 354.3, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.07}, {"Year": 2018, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 521260.0098, "Electricity from fossil fuels (TWh)": 334.7, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.16}, {"Year": 2019, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 523780.0293, "Electricity from fossil fuels (TWh)": 335.24, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.21}, {"Year": 2020, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 337.82, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.21}, {"Year": 2000, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 284660, "Electricity from fossil fuels (TWh)": 181.67, "Electricity from nuclear (TWh)": 13.01, "Electricity from renewables (TWh)": 1.79}, {"Year": 2001, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 320540, "Electricity from fossil fuels (TWh)": 183.36, "Electricity from nuclear (TWh)": 10.72, "Electricity from renewables (TWh)": 2.46}, {"Year": 2002, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 331320.0073, "Electricity from fossil fuels (TWh)": 188.79, "Electricity from nuclear (TWh)": 11.99, "Electricity from renewables (TWh)": 2.81}, {"Year": 2003, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 353089.9963, "Electricity from fossil fuels (TWh)": 204.39, "Electricity from nuclear (TWh)": 12.66, "Electricity from renewables (TWh)": 1.19}, {"Year": 2004, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 379989.9902, "Electricity from fossil fuels (TWh)": 212.63, "Electricity from nuclear (TWh)": 14.28, "Electricity from renewables (TWh)": 1.33}, {"Year": 2005, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 377649.9939, "Electricity from fossil fuels (TWh)": 215.23, "Electricity from nuclear (TWh)": 12.24, "Electricity from renewables (TWh)": 1.75}, {"Year": 2006, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 379790.0085, "Electricity from fossil fuels (TWh)": 223.25, "Electricity from nuclear (TWh)": 10.07, "Electricity from renewables (TWh)": 3.28}, {"Year": 2007, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 397059.9976, "Electricity from fossil fuels (TWh)": 232.91, "Electricity from nuclear (TWh)": 12.6, "Electricity from renewables (TWh)": 1.3}, {"Year": 2008, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 426739.9902, "Electricity from fossil fuels (TWh)": 226.32, "Electricity from nuclear (TWh)": 12.75, "Electricity from renewables (TWh)": 1.66}, {"Year": 2009, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 404200.0122, "Electricity from fossil fuels (TWh)": 218.17, "Electricity from nuclear (TWh)": 11.57, "Electricity from renewables (TWh)": 1.86}, {"Year": 2010, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 425309.9976, "Electricity from fossil fuels (TWh)": 227.57, "Electricity from nuclear (TWh)": 12.9, "Electricity from renewables (TWh)": 2.51}, {"Year": 2011, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 409260.0098, "Electricity from fossil fuels (TWh)": 229.06, "Electricity from nuclear (TWh)": 12.94, "Electricity from renewables (TWh)": 2.49}, {"Year": 2012, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 426779.9988, "Electricity from fossil fuels (TWh)": 226.84, "Electricity from nuclear (TWh)": 12.4, "Electricity from renewables (TWh)": 1.66}, {"Year": 2013, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 436920.0134, "Electricity from fossil fuels (TWh)": 223.28, "Electricity from nuclear (TWh)": 13.61, "Electricity from renewables (TWh)": 1.62}, {"Year": 2014, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 447929.9927, "Electricity from fossil fuels (TWh)": 218.42, "Electricity from nuclear (TWh)": 14.76, "Electricity from renewables (TWh)": 3.38}, {"Year": 2015, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 424809.9976, "Electricity from fossil fuels (TWh)": 214.88, "Electricity from nuclear (TWh)": 10.97, "Electricity from renewables (TWh)": 6.09}, {"Year": 2016, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 425140.0146, "Electricity from fossil fuels (TWh)": 213.09, "Electricity from nuclear (TWh)": 15.21, "Electricity from renewables (TWh)": 7.69}, {"Year": 2017, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 435649.9939, "Electricity from fossil fuels (TWh)": 212.77, "Electricity from nuclear (TWh)": 15.09, "Electricity from renewables (TWh)": 10.04}, {"Year": 2018, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 434350.0061, "Electricity from fossil fuels (TWh)": 214.25, "Electricity from nuclear (TWh)": 10.56, "Electricity from renewables (TWh)": 12.22}, {"Year": 2019, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 439640.0146, "Electricity from fossil fuels (TWh)": 208.39, "Electricity from nuclear (TWh)": 13.6, "Electricity from renewables (TWh)": 12.57}, {"Year": 2020, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 197.5, "Electricity from nuclear (TWh)": 11.62, "Electricity from renewables (TWh)": 12.83}, {"Year": 2000, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 293310, "Electricity from fossil fuels (TWh)": 124.22, "Electricity from nuclear (TWh)": 62.21, "Electricity from renewables (TWh)": 34.49}, {"Year": 2001, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 294790, "Electricity from fossil fuels (TWh)": 120.06, "Electricity from nuclear (TWh)": 63.71, "Electricity from renewables (TWh)": 49.3}, {"Year": 2002, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 312750, "Electricity from fossil fuels (TWh)": 143.72, "Electricity from nuclear (TWh)": 63.02, "Electricity from renewables (TWh)": 33.17}, {"Year": 2003, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 318660.0037, "Electricity from fossil fuels (TWh)": 139.67, "Electricity from nuclear (TWh)": 61.88, "Electricity from renewables (TWh)": 55.75}, {"Year": 2004, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 335559.9976, "Electricity from fossil fuels (TWh)": 159.91, "Electricity from nuclear (TWh)": 63.61, "Electricity from renewables (TWh)": 50.13}, {"Year": 2005, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 350500, "Electricity from fossil fuels (TWh)": 184.65, "Electricity from nuclear (TWh)": 57.54, "Electricity from renewables (TWh)": 42.27}, {"Year": 2006, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 341779.9988, "Electricity from fossil fuels (TWh)": 182.98, "Electricity from nuclear (TWh)": 60.13, "Electricity from renewables (TWh)": 52.15}, {"Year": 2007, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 354679.9927, "Electricity from fossil fuels (TWh)": 188.13, "Electricity from nuclear (TWh)": 55.1, "Electricity from renewables (TWh)": 58.3}, {"Year": 2008, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 324269.989, "Electricity from fossil fuels (TWh)": 189.55, "Electricity from nuclear (TWh)": 58.97, "Electricity from renewables (TWh)": 62.15}, {"Year": 2009, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 287489.9902, "Electricity from fossil fuels (TWh)": 164.69, "Electricity from nuclear (TWh)": 52.76, "Electricity from renewables (TWh)": 74.08}, {"Year": 2010, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 273250, "Electricity from fossil fuels (TWh)": 138.39, "Electricity from nuclear (TWh)": 61.99, "Electricity from renewables (TWh)": 97.77}, {"Year": 2011, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 274399.9939, "Electricity from fossil fuels (TWh)": 146.12, "Electricity from nuclear (TWh)": 57.72, "Electricity from renewables (TWh)": 87.53}, {"Year": 2012, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 269269.989, "Electricity from fossil fuels (TWh)": 145.33, "Electricity from nuclear (TWh)": 61.47, "Electricity from renewables (TWh)": 86.97}, {"Year": 2013, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 242809.9976, "Electricity from fossil fuels (TWh)": 113.32, "Electricity from nuclear (TWh)": 56.73, "Electricity from renewables (TWh)": 111.42}, {"Year": 2014, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 240960.0067, "Electricity from fossil fuels (TWh)": 107.37, "Electricity from nuclear (TWh)": 57.31, "Electricity from renewables (TWh)": 110.26}, {"Year": 2015, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 256279.9988, "Electricity from fossil fuels (TWh)": 123.19, "Electricity from nuclear (TWh)": 57.2, "Electricity from renewables (TWh)": 97.09}, {"Year": 2016, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 247029.9988, "Electricity from fossil fuels (TWh)": 107.93, "Electricity from nuclear (TWh)": 58.63, "Electricity from renewables (TWh)": 104.63}, {"Year": 2017, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 263450.0122, "Electricity from fossil fuels (TWh)": 126.93, "Electricity from nuclear (TWh)": 58.04, "Electricity from renewables (TWh)": 87.93}, {"Year": 2018, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 257040.0085, "Electricity from fossil fuels (TWh)": 112.23, "Electricity from nuclear (TWh)": 55.77, "Electricity from renewables (TWh)": 103.88}, {"Year": 2019, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 239979.9957, "Electricity from fossil fuels (TWh)": 111.55, "Electricity from nuclear (TWh)": 58.35, "Electricity from renewables (TWh)": 100.99}, {"Year": 2020, "Entity": "Spain", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 87.64, "Electricity from nuclear (TWh)": 58.3, "Electricity from renewables (TWh)": 113.79}, {"Year": 2000, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 164490, "Electricity from fossil fuels (TWh)": 83.15, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 6.38}, {"Year": 2001, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 173160, "Electricity from fossil fuels (TWh)": 88.97, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 6.76}, {"Year": 2002, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 184240.0055, "Electricity from fossil fuels (TWh)": 93.51, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.07}, {"Year": 2003, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 191929.9927, "Electricity from fossil fuels (TWh)": 100.61, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.36}, {"Year": 2004, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 210190.0024, "Electricity from fossil fuels (TWh)": 109.46, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 7.63}, {"Year": 2005, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 217770.0043, "Electricity from fossil fuels (TWh)": 115.58, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 7.42}, {"Year": 2006, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 219880.0049, "Electricity from fossil fuels (TWh)": 119.41, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 9.82}, {"Year": 2007, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 224589.9963, "Electricity from fossil fuels (TWh)": 122.12, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 10.2}, {"Year": 2008, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 227580.0018, "Electricity from fossil fuels (TWh)": 127.43, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.95}, {"Year": 2009, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 220259.9945, "Electricity from fossil fuels (TWh)": 128.09, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 9.09}, {"Year": 2010, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 234380.0049, "Electricity from fossil fuels (TWh)": 141.72, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.58}, {"Year": 2011, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 233600.0061, "Electricity from fossil fuels (TWh)": 135.31, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 11.83}, {"Year": 2012, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 250679.9927, "Electricity from fossil fuels (TWh)": 143.73, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 13.42}, {"Year": 2013, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 260700.0122, "Electricity from fossil fuels (TWh)": 148.29, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 12.33}, {"Year": 2014, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 256799.9878, "Electricity from fossil fuels (TWh)": 149.26, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 13.68}, {"Year": 2015, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 264000, "Electricity from fossil fuels (TWh)": 153.4, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 13.33}, {"Year": 2016, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 261600.0061, "Electricity from fossil fuels (TWh)": 161.79, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 15.97}, {"Year": 2017, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 258820.0073, "Electricity from fossil fuels (TWh)": 161.88, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 19.92}, {"Year": 2018, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 257049.9878, "Electricity from fossil fuels (TWh)": 156.26, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 25.84}, {"Year": 2019, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 267089.9963, "Electricity from fossil fuels (TWh)": 162.59, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 28.02}, {"Year": 2020, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 154.52, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 24.73}, {"Year": 2000, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 297380, "Electricity from fossil fuels (TWh)": 82.65, "Electricity from nuclear (TWh)": 77.34, "Electricity from renewables (TWh)": 11.28}, {"Year": 2001, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 300550, "Electricity from fossil fuels (TWh)": 84.59, "Electricity from nuclear (TWh)": 76.17, "Electricity from renewables (TWh)": 12.05}, {"Year": 2002, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 303940.0024, "Electricity from fossil fuels (TWh)": 85.93, "Electricity from nuclear (TWh)": 77.99, "Electricity from renewables (TWh)": 9.65}, {"Year": 2003, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 330230.011, "Electricity from fossil fuels (TWh)": 89.52, "Electricity from nuclear (TWh)": 81.41, "Electricity from renewables (TWh)": 9.27}, {"Year": 2004, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 307140.0146, "Electricity from fossil fuels (TWh)": 83.22, "Electricity from nuclear (TWh)": 87.02, "Electricity from renewables (TWh)": 11.78}, {"Year": 2005, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 295410.0037, "Electricity from fossil fuels (TWh)": 84.75, "Electricity from nuclear (TWh)": 88.76, "Electricity from renewables (TWh)": 12.4}, {"Year": 2006, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 303989.9902, "Electricity from fossil fuels (TWh)": 90.09, "Electricity from nuclear (TWh)": 90.22, "Electricity from renewables (TWh)": 12.92}, {"Year": 2007, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 312140.0146, "Electricity from fossil fuels (TWh)": 93.13, "Electricity from nuclear (TWh)": 92.54, "Electricity from renewables (TWh)": 10.47}, {"Year": 2008, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 301200.0122, "Electricity from fossil fuels (TWh)": 90.92, "Electricity from nuclear (TWh)": 89.84, "Electricity from renewables (TWh)": 11.82}, {"Year": 2009, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 251619.9951, "Electricity from fossil fuels (TWh)": 78.58, "Electricity from nuclear (TWh)": 82.92, "Electricity from renewables (TWh)": 12.12}, {"Year": 2010, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 268920.0134, "Electricity from fossil fuels (TWh)": 86.28, "Electricity from nuclear (TWh)": 89.15, "Electricity from renewables (TWh)": 13.39}, {"Year": 2011, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 283339.9963, "Electricity from fossil fuels (TWh)": 93.5, "Electricity from nuclear (TWh)": 90.25, "Electricity from renewables (TWh)": 11.2}, {"Year": 2012, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 277109.9854, "Electricity from fossil fuels (TWh)": 96.99, "Electricity from nuclear (TWh)": 90.14, "Electricity from renewables (TWh)": 11.23}, {"Year": 2013, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 270269.989, "Electricity from fossil fuels (TWh)": 95.39, "Electricity from nuclear (TWh)": 83.21, "Electricity from renewables (TWh)": 15.11}, {"Year": 2014, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 237729.9957, "Electricity from fossil fuels (TWh)": 83.42, "Electricity from nuclear (TWh)": 88.39, "Electricity from renewables (TWh)": 10.17}, {"Year": 2015, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 191070.0073, "Electricity from fossil fuels (TWh)": 66.91, "Electricity from nuclear (TWh)": 87.63, "Electricity from renewables (TWh)": 7.1}, {"Year": 2016, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 201660.0037, "Electricity from fossil fuels (TWh)": 72.66, "Electricity from nuclear (TWh)": 80.95, "Electricity from renewables (TWh)": 9.25}, {"Year": 2017, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 174940.0024, "Electricity from fossil fuels (TWh)": 57.96, "Electricity from nuclear (TWh)": 85.58, "Electricity from renewables (TWh)": 10.88}, {"Year": 2018, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 185619.9951, "Electricity from fossil fuels (TWh)": 60.81, "Electricity from nuclear (TWh)": 84.4, "Electricity from renewables (TWh)": 13.02}, {"Year": 2019, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 174729.9957, "Electricity from fossil fuels (TWh)": 57.79, "Electricity from nuclear (TWh)": 83, "Electricity from renewables (TWh)": 11.87}, {"Year": 2020, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 54.5, "Electricity from nuclear (TWh)": 76.2, "Electricity from renewables (TWh)": 17.56}, {"Year": 2000, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 530890, "Electricity from fossil fuels (TWh)": 279.34, "Electricity from nuclear (TWh)": 85.06, "Electricity from renewables (TWh)": 9.98}, {"Year": 2001, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 545260, "Electricity from fossil fuels (TWh)": 282.72, "Electricity from nuclear (TWh)": 90.09, "Electricity from renewables (TWh)": 9.56}, {"Year": 2002, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 530789.978, "Electricity from fossil fuels (TWh)": 285.62, "Electricity from nuclear (TWh)": 87.85, "Electricity from renewables (TWh)": 11.13}, {"Year": 2003, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 543039.978, "Electricity from fossil fuels (TWh)": 296.15, "Electricity from nuclear (TWh)": 88.69, "Electricity from renewables (TWh)": 10.62}, {"Year": 2004, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 543080.0171, "Electricity from fossil fuels (TWh)": 297.15, "Electricity from nuclear (TWh)": 80, "Electricity from renewables (TWh)": 14.14}, {"Year": 2005, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 540919.9829, "Electricity from fossil fuels (TWh)": 296.87, "Electricity from nuclear (TWh)": 81.62, "Electricity from renewables (TWh)": 16.93}, {"Year": 2006, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 542059.9976, "Electricity from fossil fuels (TWh)": 299.88, "Electricity from nuclear (TWh)": 75.45, "Electricity from renewables (TWh)": 18.11}, {"Year": 2007, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 530500, "Electricity from fossil fuels (TWh)": 310.26, "Electricity from nuclear (TWh)": 63.03, "Electricity from renewables (TWh)": 19.69}, {"Year": 2008, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 515340.0269, "Electricity from fossil fuels (TWh)": 310.5, "Electricity from nuclear (TWh)": 52.49, "Electricity from renewables (TWh)": 21.85}, {"Year": 2009, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 466489.9902, "Electricity from fossil fuels (TWh)": 278.73, "Electricity from nuclear (TWh)": 69.1, "Electricity from renewables (TWh)": 25.25}, {"Year": 2010, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 482440.0024, "Electricity from fossil fuels (TWh)": 290.59, "Electricity from nuclear (TWh)": 62.14, "Electricity from renewables (TWh)": 26.18}, {"Year": 2011, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 445589.9963, "Electricity from fossil fuels (TWh)": 260.88, "Electricity from nuclear (TWh)": 68.98, "Electricity from renewables (TWh)": 35.2}, {"Year": 2012, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 467779.9988, "Electricity from fossil fuels (TWh)": 249.25, "Electricity from nuclear (TWh)": 70.4, "Electricity from renewables (TWh)": 41.24}, {"Year": 2013, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 453760.0098, "Electricity from fossil fuels (TWh)": 231.56, "Electricity from nuclear (TWh)": 70.61, "Electricity from renewables (TWh)": 53.21}, {"Year": 2014, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 415600.0061, "Electricity from fossil fuels (TWh)": 206.94, "Electricity from nuclear (TWh)": 63.75, "Electricity from renewables (TWh)": 64.52}, {"Year": 2015, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 401079.9866, "Electricity from fossil fuels (TWh)": 182.43, "Electricity from nuclear (TWh)": 70.34, "Electricity from renewables (TWh)": 82.57}, {"Year": 2016, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 380809.9976, "Electricity from fossil fuels (TWh)": 181.56, "Electricity from nuclear (TWh)": 71.73, "Electricity from renewables (TWh)": 82.99}, {"Year": 2017, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 367000, "Electricity from fossil fuels (TWh)": 165.91, "Electricity from nuclear (TWh)": 70.34, "Electricity from renewables (TWh)": 98.85}, {"Year": 2018, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 360730.011, "Electricity from fossil fuels (TWh)": 155.41, "Electricity from nuclear (TWh)": 65.06, "Electricity from renewables (TWh)": 110.03}, {"Year": 2019, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 348920.0134, "Electricity from fossil fuels (TWh)": 144.99, "Electricity from nuclear (TWh)": 56.18, "Electricity from renewables (TWh)": 120.48}, {"Year": 2020, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 124.78, "Electricity from nuclear (TWh)": 50.85, "Electricity from renewables (TWh)": 131.74}, {"Year": 2000, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5775810, "Electricity from fossil fuels (TWh)": 2697.28, "Electricity from nuclear (TWh)": 753.89, "Electricity from renewables (TWh)": 350.93}, {"Year": 2001, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5748260, "Electricity from fossil fuels (TWh)": 2678.68, "Electricity from nuclear (TWh)": 768.83, "Electricity from renewables (TWh)": 280.06}, {"Year": 2002, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5593029.785, "Electricity from fossil fuels (TWh)": 2727.83, "Electricity from nuclear (TWh)": 780.06, "Electricity from renewables (TWh)": 336.34}, {"Year": 2003, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5658990.234, "Electricity from fossil fuels (TWh)": 2756.03, "Electricity from nuclear (TWh)": 763.73, "Electricity from renewables (TWh)": 349.18}, {"Year": 2004, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5738290.039, "Electricity from fossil fuels (TWh)": 2818.28, "Electricity from nuclear (TWh)": 788.53, "Electricity from renewables (TWh)": 345.14}, {"Year": 2005, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5753490.234, "Electricity from fossil fuels (TWh)": 2899.96, "Electricity from nuclear (TWh)": 781.99, "Electricity from renewables (TWh)": 353.04}, {"Year": 2006, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5653080.078, "Electricity from fossil fuels (TWh)": 2878.56, "Electricity from nuclear (TWh)": 787.22, "Electricity from renewables (TWh)": 381.16}, {"Year": 2007, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5736319.824, "Electricity from fossil fuels (TWh)": 2988.24, "Electricity from nuclear (TWh)": 806.42, "Electricity from renewables (TWh)": 347.91}, {"Year": 2008, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5558379.883, "Electricity from fossil fuels (TWh)": 2924.21, "Electricity from nuclear (TWh)": 806.21, "Electricity from renewables (TWh)": 377.11}, {"Year": 2009, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5156430.176, "Electricity from fossil fuels (TWh)": 2725.41, "Electricity from nuclear (TWh)": 798.85, "Electricity from renewables (TWh)": 415.56}, {"Year": 2010, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5392109.863, "Electricity from fossil fuels (TWh)": 2882.49, "Electricity from nuclear (TWh)": 806.97, "Electricity from renewables (TWh)": 424.48}, {"Year": 2011, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5173600.098, "Electricity from fossil fuels (TWh)": 2788.93, "Electricity from nuclear (TWh)": 790.2, "Electricity from renewables (TWh)": 509.74}, {"Year": 2012, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4956060.059, "Electricity from fossil fuels (TWh)": 2779.02, "Electricity from nuclear (TWh)": 769.33, "Electricity from renewables (TWh)": 492.32}, {"Year": 2013, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5092100.098, "Electricity from fossil fuels (TWh)": 2746.21, "Electricity from nuclear (TWh)": 789.02, "Electricity from renewables (TWh)": 520.38}, {"Year": 2014, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5107209.961, "Electricity from fossil fuels (TWh)": 2752.01, "Electricity from nuclear (TWh)": 797.17, "Electricity from renewables (TWh)": 546.83}, {"Year": 2015, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4990709.961, "Electricity from fossil fuels (TWh)": 2730.32, "Electricity from nuclear (TWh)": 797.18, "Electricity from renewables (TWh)": 556.49}, {"Year": 2016, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4894500, "Electricity from fossil fuels (TWh)": 2656.96, "Electricity from nuclear (TWh)": 805.69, "Electricity from renewables (TWh)": 624.91}, {"Year": 2017, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4819370.117, "Electricity from fossil fuels (TWh)": 2540.17, "Electricity from nuclear (TWh)": 804.95, "Electricity from renewables (TWh)": 707.19}, {"Year": 2018, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4975310.059, "Electricity from fossil fuels (TWh)": 2661.3, "Electricity from nuclear (TWh)": 807.08, "Electricity from renewables (TWh)": 733.17}, {"Year": 2019, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4817720.215, "Electricity from fossil fuels (TWh)": 2588.21, "Electricity from nuclear (TWh)": 809.41, "Electricity from renewables (TWh)": 760.76}, {"Year": 2020, "Entity": "United States", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 2431.9, "Electricity from nuclear (TWh)": 789.88, "Electricity from renewables (TWh)": 821.4}], "anchored": true, "attachedMetadata": ""}, {"kind": "table", "id": "table-82", "displayId": "energy-source", "names": ["Entity", "Year", "energy", "source"], "rows": [{"Entity": "Australia", "Year": 2000, "energy": 181.05, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2001, "energy": 194.33, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2002, "energy": 197.29, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2003, "energy": 195.13, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2004, "energy": 203.66, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2005, "energy": 195.95, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2006, "energy": 198.72, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2007, "energy": 208.59, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2008, "energy": 211.06, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2009, "energy": 216.42, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2010, "energy": 212.5, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2011, "energy": 213.56, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2012, "energy": 206.75, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2013, "energy": 195.78, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2014, "energy": 205.46, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2015, "energy": 197.72, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2016, "energy": 207.66, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2017, "energy": 209.14, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2018, "energy": 207.45, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2019, "energy": 196.45, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2020, "energy": 186.92, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2000, "energy": 28.87, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2001, "energy": 35.19, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2002, "energy": 33.5, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2003, "energy": 31.62, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2004, "energy": 40.14, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2005, "energy": 39.56, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2006, "energy": 39.4, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2007, "energy": 37.64, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2008, "energy": 55.87, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2009, "energy": 36.32, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2010, "energy": 61.02, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2011, "energy": 50.27, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2012, "energy": 77.21, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2013, "energy": 112, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2014, "energy": 136.58, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2015, "energy": 128.85, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2016, "energy": 93.06, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2017, "energy": 101.9, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2018, "energy": 86.69, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2019, "energy": 90.91, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2020, "energy": 81.15, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2000, "energy": 155.56, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2001, "energy": 159.93, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2002, "energy": 155.12, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2003, "energy": 157.35, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2004, "energy": 148.86, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2005, "energy": 150.78, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2006, "energy": 139.71, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2007, "energy": 149.36, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2008, "energy": 141.33, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2009, "energy": 129.76, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2010, "energy": 130.08, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2011, "energy": 131.3, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2012, "energy": 124.2, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2013, "energy": 122.87, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2014, "energy": 122.75, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2015, "energy": 125.7, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2016, "energy": 122.35, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2017, "energy": 113.7, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2018, "energy": 112.47, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2019, "energy": 110.65, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2020, "energy": 102.19, "source": "fossil fuels"}, {"Entity": "China", "Year": 2000, "energy": 1113.3, "source": "fossil fuels"}, {"Entity": "China", "Year": 2001, "energy": 1182.59, "source": "fossil fuels"}, {"Entity": "China", "Year": 2002, "energy": 1337.46, "source": "fossil fuels"}, {"Entity": "China", "Year": 2003, "energy": 1579.96, "source": "fossil fuels"}, {"Entity": "China", "Year": 2004, "energy": 1795.41, "source": "fossil fuels"}, {"Entity": "China", "Year": 2005, "energy": 2042.8, "source": "fossil fuels"}, {"Entity": "China", "Year": 2006, "energy": 2364.16, "source": "fossil fuels"}, {"Entity": "China", "Year": 2007, "energy": 2718.7, "source": "fossil fuels"}, {"Entity": "China", "Year": 2008, "energy": 2762.29, "source": "fossil fuels"}, {"Entity": "China", "Year": 2009, "energy": 2980.2, "source": "fossil fuels"}, {"Entity": "China", "Year": 2010, "energy": 3326.19, "source": "fossil fuels"}, {"Entity": "China", "Year": 2011, "energy": 3811.77, "source": "fossil fuels"}, {"Entity": "China", "Year": 2012, "energy": 3869.38, "source": "fossil fuels"}, {"Entity": "China", "Year": 2013, "energy": 4203.77, "source": "fossil fuels"}, {"Entity": "China", "Year": 2014, "energy": 4345.86, "source": "fossil fuels"}, {"Entity": "China", "Year": 2015, "energy": 4222.76, "source": "fossil fuels"}, {"Entity": "China", "Year": 2016, "energy": 4355, "source": "fossil fuels"}, {"Entity": "China", "Year": 2017, "energy": 4643.1, "source": "fossil fuels"}, {"Entity": "China", "Year": 2018, "energy": 4990.28, "source": "fossil fuels"}, {"Entity": "China", "Year": 2019, "energy": 5098.22, "source": "fossil fuels"}, {"Entity": "China", "Year": 2020, "energy": 5184.13, "source": "fossil fuels"}, {"Entity": "France", "Year": 2000, "energy": 50.61, "source": "fossil fuels"}, {"Entity": "France", "Year": 2001, "energy": 46.48, "source": "fossil fuels"}, {"Entity": "France", "Year": 2002, "energy": 52.67, "source": "fossil fuels"}, {"Entity": "France", "Year": 2003, "energy": 57.38, "source": "fossil fuels"}, {"Entity": "France", "Year": 2004, "energy": 56.53, "source": "fossil fuels"}, {"Entity": "France", "Year": 2005, "energy": 63.35, "source": "fossil fuels"}, {"Entity": "France", "Year": 2006, "energy": 56.9, "source": "fossil fuels"}, {"Entity": "France", "Year": 2007, "energy": 58.18, "source": "fossil fuels"}, {"Entity": "France", "Year": 2008, "energy": 55.57, "source": "fossil fuels"}, {"Entity": "France", "Year": 2009, "energy": 51.32, "source": "fossil fuels"}, {"Entity": "France", "Year": 2010, "energy": 57.63, "source": "fossil fuels"}, {"Entity": "France", "Year": 2011, "energy": 58.99, "source": "fossil fuels"}, {"Entity": "France", "Year": 2012, "energy": 56.42, "source": "fossil fuels"}, {"Entity": "France", "Year": 2013, "energy": 53.35, "source": "fossil fuels"}, {"Entity": "France", "Year": 2014, "energy": 35.68, "source": "fossil fuels"}, {"Entity": "France", "Year": 2015, "energy": 44.65, "source": "fossil fuels"}, {"Entity": "France", "Year": 2016, "energy": 56.45, "source": "fossil fuels"}, {"Entity": "France", "Year": 2017, "energy": 65.09, "source": "fossil fuels"}, {"Entity": "France", "Year": 2018, "energy": 49.27, "source": "fossil fuels"}, {"Entity": "France", "Year": 2019, "energy": 53.5, "source": "fossil fuels"}, {"Entity": "France", "Year": 2020, "energy": 48.14, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2000, "energy": 367.22, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2001, "energy": 372.69, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2002, "energy": 372.64, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2003, "energy": 390.81, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2004, "energy": 385.24, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2005, "energy": 386.96, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2006, "energy": 390.03, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2007, "energy": 402.4, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2008, "energy": 390.43, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2009, "energy": 358.07, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2010, "energy": 378.9, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2011, "energy": 373.16, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2012, "energy": 377.89, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2013, "energy": 381.52, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2014, "energy": 360.28, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2015, "energy": 359.99, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2016, "energy": 368.67, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2017, "energy": 353.37, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2018, "energy": 334.65, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2019, "energy": 284.09, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2020, "energy": 251.4, "source": "fossil fuels"}, {"Entity": "India", "Year": 2000, "energy": 475.35, "source": "fossil fuels"}, {"Entity": "India", "Year": 2001, "energy": 491.01, "source": "fossil fuels"}, {"Entity": "India", "Year": 2002, "energy": 517.51, "source": "fossil fuels"}, {"Entity": "India", "Year": 2003, "energy": 545.36, "source": "fossil fuels"}, {"Entity": "India", "Year": 2004, "energy": 567.86, "source": "fossil fuels"}, {"Entity": "India", "Year": 2005, "energy": 579.32, "source": "fossil fuels"}, {"Entity": "India", "Year": 2006, "energy": 599.24, "source": "fossil fuels"}, {"Entity": "India", "Year": 2007, "energy": 636.68, "source": "fossil fuels"}, {"Entity": "India", "Year": 2008, "energy": 674.27, "source": "fossil fuels"}, {"Entity": "India", "Year": 2009, "energy": 728.56, "source": "fossil fuels"}, {"Entity": "India", "Year": 2010, "energy": 771.78, "source": "fossil fuels"}, {"Entity": "India", "Year": 2011, "energy": 828.16, "source": "fossil fuels"}, {"Entity": "India", "Year": 2012, "energy": 893.45, "source": "fossil fuels"}, {"Entity": "India", "Year": 2013, "energy": 924.93, "source": "fossil fuels"}, {"Entity": "India", "Year": 2014, "energy": 1025.29, "source": "fossil fuels"}, {"Entity": "India", "Year": 2015, "energy": 1080.44, "source": "fossil fuels"}, {"Entity": "India", "Year": 2016, "energy": 1155.52, "source": "fossil fuels"}, {"Entity": "India", "Year": 2017, "energy": 1198.85, "source": "fossil fuels"}, {"Entity": "India", "Year": 2018, "energy": 1276.32, "source": "fossil fuels"}, {"Entity": "India", "Year": 2019, "energy": 1273.59, "source": "fossil fuels"}, {"Entity": "India", "Year": 2020, "energy": 1202.34, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2000, "energy": 78.43, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2001, "energy": 83.96, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2002, "energy": 92.03, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2003, "energy": 97.57, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2004, "energy": 103.8, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2005, "energy": 110.22, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2006, "energy": 116.8, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2007, "energy": 124.1, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2008, "energy": 129.55, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2009, "energy": 136.05, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2010, "energy": 142.88, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2011, "energy": 161.41, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2012, "energy": 177.83, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2013, "energy": 189.66, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2014, "energy": 203.11, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2015, "energy": 209.71, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2016, "energy": 217.97, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2017, "energy": 222.64, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2018, "energy": 235.41, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2019, "energy": 247.39, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2020, "energy": 238.91, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2000, "energy": 218.28, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2001, "energy": 216.73, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2002, "energy": 228.45, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2003, "energy": 238.52, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2004, "energy": 240.95, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2005, "energy": 247.29, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2006, "energy": 256.03, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2007, "energy": 259.49, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2008, "energy": 254.34, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2009, "energy": 218.32, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2010, "energy": 220.93, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2011, "energy": 216.78, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2012, "energy": 204.26, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2013, "energy": 175.07, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2014, "energy": 156.76, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2015, "energy": 172.06, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2016, "energy": 179.19, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2017, "energy": 189.44, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2018, "energy": 172.98, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2019, "energy": 175.52, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2020, "energy": 161.17, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2000, "energy": 578.29, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2001, "energy": 564.95, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2002, "energy": 605.12, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2003, "energy": 633.76, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2004, "energy": 621.6, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2005, "energy": 634.09, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2006, "energy": 628.77, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2007, "energy": 705.37, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2008, "energy": 663.88, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2009, "energy": 611.86, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2010, "energy": 689.89, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2011, "energy": 777.1, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2012, "energy": 920.39, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2013, "energy": 897.88, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2014, "energy": 892.18, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2015, "energy": 844.23, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2016, "energy": 832.4, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2017, "energy": 806.12, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2018, "energy": 780.61, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2019, "energy": 735.66, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2020, "energy": 716.67, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2000, "energy": 44.11, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2001, "energy": 47.3, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2002, "energy": 49.44, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2003, "energy": 55.24, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2004, "energy": 58.89, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2005, "energy": 60.06, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2006, "energy": 63.89, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2007, "energy": 68.45, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2008, "energy": 72.89, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2009, "energy": 71.85, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2010, "energy": 74.63, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2011, "energy": 78.7, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2012, "energy": 82.98, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2013, "energy": 84.88, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2014, "energy": 86.37, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2015, "energy": 82.2, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2016, "energy": 82.65, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2017, "energy": 91.48, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2018, "energy": 96.36, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2019, "energy": 95.39, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2020, "energy": 96.7, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2000, "energy": 141.8, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2001, "energy": 153.32, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2002, "energy": 159.81, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2003, "energy": 160.45, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2004, "energy": 173.66, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2005, "energy": 178.76, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2006, "energy": 182.76, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2007, "energy": 191.83, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2008, "energy": 184.51, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2009, "energy": 194.75, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2010, "energy": 207.38, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2011, "energy": 219.88, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2012, "energy": 229.14, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2013, "energy": 231.23, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2014, "energy": 223.43, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2015, "energy": 234.28, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2016, "energy": 239.78, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2017, "energy": 242.69, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2018, "energy": 259.92, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2019, "energy": 248.2, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2020, "energy": 245.46, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2000, "energy": 140.85, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2001, "energy": 140.94, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2002, "energy": 139.72, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2003, "energy": 147.76, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2004, "energy": 149.06, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2005, "energy": 151.2, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2006, "energy": 156.16, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2007, "energy": 153.08, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2008, "energy": 148.03, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2009, "energy": 142.4, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2010, "energy": 146.12, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2011, "energy": 149.88, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2012, "energy": 144.75, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2013, "energy": 146.85, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2014, "energy": 138.53, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2015, "energy": 141.55, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2016, "energy": 143.28, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2017, "energy": 145.8, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2018, "energy": 147.87, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2019, "energy": 137.58, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2020, "energy": 128.91, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2000, "energy": 138.68, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2001, "energy": 146.09, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2002, "energy": 154.91, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2003, "energy": 166.58, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2004, "energy": 173.41, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2005, "energy": 191.05, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2006, "energy": 196.31, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2007, "energy": 204.43, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2008, "energy": 204.2, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2009, "energy": 217.31, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2010, "energy": 240.06, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2011, "energy": 250.07, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2012, "energy": 271.68, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2013, "energy": 284.02, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2014, "energy": 311.81, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2015, "energy": 338.34, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2016, "energy": 337.38, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2017, "energy": 354.3, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2018, "energy": 334.7, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2019, "energy": 335.24, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2020, "energy": 337.82, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2000, "energy": 181.67, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2001, "energy": 183.36, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2002, "energy": 188.79, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2003, "energy": 204.39, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2004, "energy": 212.63, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2005, "energy": 215.23, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2006, "energy": 223.25, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2007, "energy": 232.91, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2008, "energy": 226.32, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2009, "energy": 218.17, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2010, "energy": 227.57, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2011, "energy": 229.06, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2012, "energy": 226.84, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2013, "energy": 223.28, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2014, "energy": 218.42, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2015, "energy": 214.88, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2016, "energy": 213.09, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2017, "energy": 212.77, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2018, "energy": 214.25, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2019, "energy": 208.39, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2020, "energy": 197.5, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2000, "energy": 124.22, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2001, "energy": 120.06, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2002, "energy": 143.72, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2003, "energy": 139.67, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2004, "energy": 159.91, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2005, "energy": 184.65, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2006, "energy": 182.98, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2007, "energy": 188.13, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2008, "energy": 189.55, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2009, "energy": 164.69, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2010, "energy": 138.39, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2011, "energy": 146.12, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2012, "energy": 145.33, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2013, "energy": 113.32, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2014, "energy": 107.37, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2015, "energy": 123.19, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2016, "energy": 107.93, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2017, "energy": 126.93, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2018, "energy": 112.23, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2019, "energy": 111.55, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2020, "energy": 87.64, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2000, "energy": 83.15, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2001, "energy": 88.97, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2002, "energy": 93.51, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2003, "energy": 100.61, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2004, "energy": 109.46, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2005, "energy": 115.58, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2006, "energy": 119.41, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2007, "energy": 122.12, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2008, "energy": 127.43, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2009, "energy": 128.09, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2010, "energy": 141.72, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2011, "energy": 135.31, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2012, "energy": 143.73, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2013, "energy": 148.29, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2014, "energy": 149.26, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2015, "energy": 153.4, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2016, "energy": 161.79, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2017, "energy": 161.88, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2018, "energy": 156.26, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2019, "energy": 162.59, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2020, "energy": 154.52, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2000, "energy": 82.65, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2001, "energy": 84.59, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2002, "energy": 85.93, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2003, "energy": 89.52, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2004, "energy": 83.22, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2005, "energy": 84.75, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2006, "energy": 90.09, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2007, "energy": 93.13, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2008, "energy": 90.92, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2009, "energy": 78.58, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2010, "energy": 86.28, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2011, "energy": 93.5, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2012, "energy": 96.99, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2013, "energy": 95.39, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2014, "energy": 83.42, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2015, "energy": 66.91, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2016, "energy": 72.66, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2017, "energy": 57.96, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2018, "energy": 60.81, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2019, "energy": 57.79, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2020, "energy": 54.5, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2000, "energy": 279.34, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2001, "energy": 282.72, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2002, "energy": 285.62, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2003, "energy": 296.15, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2004, "energy": 297.15, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2005, "energy": 296.87, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2006, "energy": 299.88, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2007, "energy": 310.26, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2008, "energy": 310.5, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2009, "energy": 278.73, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2010, "energy": 290.59, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2011, "energy": 260.88, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2012, "energy": 249.25, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2013, "energy": 231.56, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2014, "energy": 206.94, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2015, "energy": 182.43, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2016, "energy": 181.56, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2017, "energy": 165.91, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2018, "energy": 155.41, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2019, "energy": 144.99, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2020, "energy": 124.78, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2000, "energy": 2697.28, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2001, "energy": 2678.68, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2002, "energy": 2727.83, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2003, "energy": 2756.03, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2004, "energy": 2818.28, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2005, "energy": 2899.96, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2006, "energy": 2878.56, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2007, "energy": 2988.24, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2008, "energy": 2924.21, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2009, "energy": 2725.41, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2010, "energy": 2882.49, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2011, "energy": 2788.93, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2012, "energy": 2779.02, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2013, "energy": 2746.21, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2014, "energy": 2752.01, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2015, "energy": 2730.32, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2016, "energy": 2656.96, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2017, "energy": 2540.17, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2018, "energy": 2661.3, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2019, "energy": 2588.21, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2020, "energy": 2431.9, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2000, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2001, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2002, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2003, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2004, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2005, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2006, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2007, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2008, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2009, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2010, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2011, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2012, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2013, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2015, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2016, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2017, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2018, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2019, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2020, "energy": 0, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2000, "energy": 4.94, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2001, "energy": 14.27, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2002, "energy": 13.84, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2003, "energy": 13.4, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2004, "energy": 11.6, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2005, "energy": 9.2, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2006, "energy": 12.98, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2007, "energy": 11.65, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2008, "energy": 13.21, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2009, "energy": 12.22, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2010, "energy": 13.77, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2011, "energy": 14.8, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2012, "energy": 15.17, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2013, "energy": 14.65, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2014, "energy": 14.46, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2015, "energy": 13.91, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2016, "energy": 14.97, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2017, "energy": 14.86, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2018, "energy": 14.79, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2019, "energy": 15.16, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2020, "energy": 13.21, "source": "nuclear"}, {"Entity": "Canada", "Year": 2000, "energy": 69.16, "source": "nuclear"}, {"Entity": "Canada", "Year": 2001, "energy": 72.86, "source": "nuclear"}, {"Entity": "Canada", "Year": 2002, "energy": 71.75, "source": "nuclear"}, {"Entity": "Canada", "Year": 2003, "energy": 71.15, "source": "nuclear"}, {"Entity": "Canada", "Year": 2004, "energy": 85.87, "source": "nuclear"}, {"Entity": "Canada", "Year": 2005, "energy": 86.83, "source": "nuclear"}, {"Entity": "Canada", "Year": 2006, "energy": 92.44, "source": "nuclear"}, {"Entity": "Canada", "Year": 2007, "energy": 88.19, "source": "nuclear"}, {"Entity": "Canada", "Year": 2008, "energy": 88.3, "source": "nuclear"}, {"Entity": "Canada", "Year": 2009, "energy": 85.13, "source": "nuclear"}, {"Entity": "Canada", "Year": 2010, "energy": 85.53, "source": "nuclear"}, {"Entity": "Canada", "Year": 2011, "energy": 88.29, "source": "nuclear"}, {"Entity": "Canada", "Year": 2012, "energy": 89.49, "source": "nuclear"}, {"Entity": "Canada", "Year": 2013, "energy": 97.58, "source": "nuclear"}, {"Entity": "Canada", "Year": 2014, "energy": 101.21, "source": "nuclear"}, {"Entity": "Canada", "Year": 2015, "energy": 96.05, "source": "nuclear"}, {"Entity": "Canada", "Year": 2016, "energy": 95.69, "source": "nuclear"}, {"Entity": "Canada", "Year": 2017, "energy": 95.57, "source": "nuclear"}, {"Entity": "Canada", "Year": 2018, "energy": 95.03, "source": "nuclear"}, {"Entity": "Canada", "Year": 2019, "energy": 95.47, "source": "nuclear"}, {"Entity": "Canada", "Year": 2020, "energy": 92.65, "source": "nuclear"}, {"Entity": "China", "Year": 2000, "energy": 16.74, "source": "nuclear"}, {"Entity": "China", "Year": 2001, "energy": 17.47, "source": "nuclear"}, {"Entity": "China", "Year": 2002, "energy": 25.13, "source": "nuclear"}, {"Entity": "China", "Year": 2003, "energy": 43.34, "source": "nuclear"}, {"Entity": "China", "Year": 2004, "energy": 50.47, "source": "nuclear"}, {"Entity": "China", "Year": 2005, "energy": 53.09, "source": "nuclear"}, {"Entity": "China", "Year": 2006, "energy": 54.84, "source": "nuclear"}, {"Entity": "China", "Year": 2007, "energy": 62.13, "source": "nuclear"}, {"Entity": "China", "Year": 2008, "energy": 68.39, "source": "nuclear"}, {"Entity": "China", "Year": 2009, "energy": 70.05, "source": "nuclear"}, {"Entity": "China", "Year": 2010, "energy": 74.74, "source": "nuclear"}, {"Entity": "China", "Year": 2011, "energy": 87.2, "source": "nuclear"}, {"Entity": "China", "Year": 2012, "energy": 98.32, "source": "nuclear"}, {"Entity": "China", "Year": 2013, "energy": 111.5, "source": "nuclear"}, {"Entity": "China", "Year": 2014, "energy": 133.22, "source": "nuclear"}, {"Entity": "China", "Year": 2015, "energy": 171.38, "source": "nuclear"}, {"Entity": "China", "Year": 2016, "energy": 213.18, "source": "nuclear"}, {"Entity": "China", "Year": 2017, "energy": 248.1, "source": "nuclear"}, {"Entity": "China", "Year": 2018, "energy": 295, "source": "nuclear"}, {"Entity": "China", "Year": 2019, "energy": 348.7, "source": "nuclear"}, {"Entity": "China", "Year": 2020, "energy": 366.2, "source": "nuclear"}, {"Entity": "France", "Year": 2000, "energy": 415.16, "source": "nuclear"}, {"Entity": "France", "Year": 2001, "energy": 421.08, "source": "nuclear"}, {"Entity": "France", "Year": 2002, "energy": 436.76, "source": "nuclear"}, {"Entity": "France", "Year": 2003, "energy": 441.07, "source": "nuclear"}, {"Entity": "France", "Year": 2004, "energy": 448.24, "source": "nuclear"}, {"Entity": "France", "Year": 2005, "energy": 451.53, "source": "nuclear"}, {"Entity": "France", "Year": 2006, "energy": 450.19, "source": "nuclear"}, {"Entity": "France", "Year": 2007, "energy": 439.73, "source": "nuclear"}, {"Entity": "France", "Year": 2008, "energy": 439.45, "source": "nuclear"}, {"Entity": "France", "Year": 2009, "energy": 409.74, "source": "nuclear"}, {"Entity": "France", "Year": 2010, "energy": 428.52, "source": "nuclear"}, {"Entity": "France", "Year": 2011, "energy": 442.39, "source": "nuclear"}, {"Entity": "France", "Year": 2012, "energy": 425.41, "source": "nuclear"}, {"Entity": "France", "Year": 2013, "energy": 423.68, "source": "nuclear"}, {"Entity": "France", "Year": 2014, "energy": 436.48, "source": "nuclear"}, {"Entity": "France", "Year": 2015, "energy": 437.43, "source": "nuclear"}, {"Entity": "France", "Year": 2016, "energy": 403.2, "source": "nuclear"}, {"Entity": "France", "Year": 2017, "energy": 398.36, "source": "nuclear"}, {"Entity": "France", "Year": 2018, "energy": 412.94, "source": "nuclear"}, {"Entity": "France", "Year": 2019, "energy": 399.01, "source": "nuclear"}, {"Entity": "France", "Year": 2020, "energy": 353.83, "source": "nuclear"}, {"Entity": "Germany", "Year": 2000, "energy": 169.61, "source": "nuclear"}, {"Entity": "Germany", "Year": 2001, "energy": 171.3, "source": "nuclear"}, {"Entity": "Germany", "Year": 2002, "energy": 164.84, "source": "nuclear"}, {"Entity": "Germany", "Year": 2003, "energy": 165.06, "source": "nuclear"}, {"Entity": "Germany", "Year": 2004, "energy": 167.07, "source": "nuclear"}, {"Entity": "Germany", "Year": 2005, "energy": 163.05, "source": "nuclear"}, {"Entity": "Germany", "Year": 2006, "energy": 167.27, "source": "nuclear"}, {"Entity": "Germany", "Year": 2007, "energy": 140.53, "source": "nuclear"}, {"Entity": "Germany", "Year": 2008, "energy": 148.49, "source": "nuclear"}, {"Entity": "Germany", "Year": 2009, "energy": 134.93, "source": "nuclear"}, {"Entity": "Germany", "Year": 2010, "energy": 140.56, "source": "nuclear"}, {"Entity": "Germany", "Year": 2011, "energy": 107.97, "source": "nuclear"}, {"Entity": "Germany", "Year": 2012, "energy": 99.46, "source": "nuclear"}, {"Entity": "Germany", "Year": 2013, "energy": 97.29, "source": "nuclear"}, {"Entity": "Germany", "Year": 2014, "energy": 97.13, "source": "nuclear"}, {"Entity": "Germany", "Year": 2015, "energy": 91.79, "source": "nuclear"}, {"Entity": "Germany", "Year": 2016, "energy": 84.63, "source": "nuclear"}, {"Entity": "Germany", "Year": 2017, "energy": 76.32, "source": "nuclear"}, {"Entity": "Germany", "Year": 2018, "energy": 76, "source": "nuclear"}, {"Entity": "Germany", "Year": 2019, "energy": 75.07, "source": "nuclear"}, {"Entity": "Germany", "Year": 2020, "energy": 64.38, "source": "nuclear"}, {"Entity": "India", "Year": 2000, "energy": 15.77, "source": "nuclear"}, {"Entity": "India", "Year": 2001, "energy": 18.89, "source": "nuclear"}, {"Entity": "India", "Year": 2002, "energy": 19.35, "source": "nuclear"}, {"Entity": "India", "Year": 2003, "energy": 18.14, "source": "nuclear"}, {"Entity": "India", "Year": 2004, "energy": 21.26, "source": "nuclear"}, {"Entity": "India", "Year": 2005, "energy": 17.73, "source": "nuclear"}, {"Entity": "India", "Year": 2006, "energy": 17.63, "source": "nuclear"}, {"Entity": "India", "Year": 2007, "energy": 17.83, "source": "nuclear"}, {"Entity": "India", "Year": 2008, "energy": 15.23, "source": "nuclear"}, {"Entity": "India", "Year": 2009, "energy": 16.82, "source": "nuclear"}, {"Entity": "India", "Year": 2010, "energy": 23.08, "source": "nuclear"}, {"Entity": "India", "Year": 2011, "energy": 32.22, "source": "nuclear"}, {"Entity": "India", "Year": 2012, "energy": 33.14, "source": "nuclear"}, {"Entity": "India", "Year": 2013, "energy": 33.31, "source": "nuclear"}, {"Entity": "India", "Year": 2014, "energy": 34.69, "source": "nuclear"}, {"Entity": "India", "Year": 2015, "energy": 38.31, "source": "nuclear"}, {"Entity": "India", "Year": 2016, "energy": 37.9, "source": "nuclear"}, {"Entity": "India", "Year": 2017, "energy": 37.41, "source": "nuclear"}, {"Entity": "India", "Year": 2018, "energy": 39.05, "source": "nuclear"}, {"Entity": "India", "Year": 2019, "energy": 45.16, "source": "nuclear"}, {"Entity": "India", "Year": 2020, "energy": 44.61, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2000, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2001, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2002, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2003, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2004, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2005, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2006, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2007, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2008, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2009, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2010, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2011, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2012, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2013, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2014, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2015, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2016, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2017, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2018, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2019, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2020, "energy": null, "source": "nuclear"}, {"Entity": "Italy", "Year": 2000, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2001, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2002, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2003, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2004, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2005, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2006, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2007, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2008, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2009, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2010, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2011, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2012, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2013, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2015, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2016, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2017, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2018, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2019, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2020, "energy": 0, "source": "nuclear"}, {"Entity": "Japan", "Year": 2000, "energy": 305.95, "source": "nuclear"}, {"Entity": "Japan", "Year": 2001, "energy": 303.86, "source": "nuclear"}, {"Entity": "Japan", "Year": 2002, "energy": 280.34, "source": "nuclear"}, {"Entity": "Japan", "Year": 2003, "energy": 228.01, "source": "nuclear"}, {"Entity": "Japan", "Year": 2004, "energy": 268.32, "source": "nuclear"}, {"Entity": "Japan", "Year": 2005, "energy": 280.5, "source": "nuclear"}, {"Entity": "Japan", "Year": 2006, "energy": 291.54, "source": "nuclear"}, {"Entity": "Japan", "Year": 2007, "energy": 267.34, "source": "nuclear"}, {"Entity": "Japan", "Year": 2008, "energy": 241.25, "source": "nuclear"}, {"Entity": "Japan", "Year": 2009, "energy": 263.05, "source": "nuclear"}, {"Entity": "Japan", "Year": 2010, "energy": 278.36, "source": "nuclear"}, {"Entity": "Japan", "Year": 2011, "energy": 153.38, "source": "nuclear"}, {"Entity": "Japan", "Year": 2012, "energy": 15.12, "source": "nuclear"}, {"Entity": "Japan", "Year": 2013, "energy": 10.43, "source": "nuclear"}, {"Entity": "Japan", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Japan", "Year": 2015, "energy": 3.24, "source": "nuclear"}, {"Entity": "Japan", "Year": 2016, "energy": 14.87, "source": "nuclear"}, {"Entity": "Japan", "Year": 2017, "energy": 27.75, "source": "nuclear"}, {"Entity": "Japan", "Year": 2018, "energy": 47.82, "source": "nuclear"}, {"Entity": "Japan", "Year": 2019, "energy": 63.88, "source": "nuclear"}, {"Entity": "Japan", "Year": 2020, "energy": 41.86, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2000, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2001, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2002, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2003, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2004, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2005, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2006, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2007, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2008, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2009, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2010, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2011, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2012, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2013, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2014, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2015, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2016, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2017, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2018, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2019, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2020, "energy": null, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2000, "energy": 7.81, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2001, "energy": 8.29, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2002, "energy": 9.26, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2003, "energy": 9.98, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2004, "energy": 8.73, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2005, "energy": 10.32, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2006, "energy": 10.4, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2007, "energy": 9.95, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2008, "energy": 9.36, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2009, "energy": 10.11, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2010, "energy": 5.66, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2011, "energy": 9.66, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2012, "energy": 8.41, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2013, "energy": 11.38, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2014, "energy": 9.3, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2015, "energy": 11.18, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2016, "energy": 10.27, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2017, "energy": 10.57, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2018, "energy": 13.32, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2019, "energy": 10.88, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2020, "energy": 10.87, "source": "nuclear"}, {"Entity": "Poland", "Year": 2000, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2001, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2002, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2003, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2004, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2005, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2006, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2007, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2008, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2009, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2010, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2011, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2012, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2013, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2015, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2016, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2017, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2018, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2019, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2020, "energy": 0, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2000, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2001, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2002, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2003, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2004, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2005, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2006, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2007, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2008, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2009, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2010, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2011, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2012, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2013, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2014, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2015, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2016, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2017, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2018, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2019, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2020, "energy": null, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2000, "energy": 13.01, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2001, "energy": 10.72, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2002, "energy": 11.99, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2003, "energy": 12.66, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2004, "energy": 14.28, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2005, "energy": 12.24, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2006, "energy": 10.07, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2007, "energy": 12.6, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2008, "energy": 12.75, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2009, "energy": 11.57, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2010, "energy": 12.9, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2011, "energy": 12.94, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2012, "energy": 12.4, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2013, "energy": 13.61, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2014, "energy": 14.76, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2015, "energy": 10.97, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2016, "energy": 15.21, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2017, "energy": 15.09, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2018, "energy": 10.56, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2019, "energy": 13.6, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2020, "energy": 11.62, "source": "nuclear"}, {"Entity": "Spain", "Year": 2000, "energy": 62.21, "source": "nuclear"}, {"Entity": "Spain", "Year": 2001, "energy": 63.71, "source": "nuclear"}, {"Entity": "Spain", "Year": 2002, "energy": 63.02, "source": "nuclear"}, {"Entity": "Spain", "Year": 2003, "energy": 61.88, "source": "nuclear"}, {"Entity": "Spain", "Year": 2004, "energy": 63.61, "source": "nuclear"}, {"Entity": "Spain", "Year": 2005, "energy": 57.54, "source": "nuclear"}, {"Entity": "Spain", "Year": 2006, "energy": 60.13, "source": "nuclear"}, {"Entity": "Spain", "Year": 2007, "energy": 55.1, "source": "nuclear"}, {"Entity": "Spain", "Year": 2008, "energy": 58.97, "source": "nuclear"}, {"Entity": "Spain", "Year": 2009, "energy": 52.76, "source": "nuclear"}, {"Entity": "Spain", "Year": 2010, "energy": 61.99, "source": "nuclear"}, {"Entity": "Spain", "Year": 2011, "energy": 57.72, "source": "nuclear"}, {"Entity": "Spain", "Year": 2012, "energy": 61.47, "source": "nuclear"}, {"Entity": "Spain", "Year": 2013, "energy": 56.73, "source": "nuclear"}, {"Entity": "Spain", "Year": 2014, "energy": 57.31, "source": "nuclear"}, {"Entity": "Spain", "Year": 2015, "energy": 57.2, "source": "nuclear"}, {"Entity": "Spain", "Year": 2016, "energy": 58.63, "source": "nuclear"}, {"Entity": "Spain", "Year": 2017, "energy": 58.04, "source": "nuclear"}, {"Entity": "Spain", "Year": 2018, "energy": 55.77, "source": "nuclear"}, {"Entity": "Spain", "Year": 2019, "energy": 58.35, "source": "nuclear"}, {"Entity": "Spain", "Year": 2020, "energy": 58.3, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2000, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2001, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2002, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2003, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2004, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2005, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2006, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2007, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2008, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2009, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2010, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2011, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2012, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2013, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2015, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2016, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2017, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2018, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2019, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2020, "energy": 0, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2000, "energy": 77.34, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2001, "energy": 76.17, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2002, "energy": 77.99, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2003, "energy": 81.41, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2004, "energy": 87.02, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2005, "energy": 88.76, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2006, "energy": 90.22, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2007, "energy": 92.54, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2008, "energy": 89.84, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2009, "energy": 82.92, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2010, "energy": 89.15, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2011, "energy": 90.25, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2012, "energy": 90.14, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2013, "energy": 83.21, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2014, "energy": 88.39, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2015, "energy": 87.63, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2016, "energy": 80.95, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2017, "energy": 85.58, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2018, "energy": 84.4, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2019, "energy": 83, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2020, "energy": 76.2, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2000, "energy": 85.06, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2001, "energy": 90.09, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2002, "energy": 87.85, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2003, "energy": 88.69, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2004, "energy": 80, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2005, "energy": 81.62, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2006, "energy": 75.45, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2007, "energy": 63.03, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2008, "energy": 52.49, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2009, "energy": 69.1, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2010, "energy": 62.14, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2011, "energy": 68.98, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2012, "energy": 70.4, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2013, "energy": 70.61, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2014, "energy": 63.75, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2015, "energy": 70.34, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2016, "energy": 71.73, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2017, "energy": 70.34, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2018, "energy": 65.06, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2019, "energy": 56.18, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2020, "energy": 50.85, "source": "nuclear"}, {"Entity": "United States", "Year": 2000, "energy": 753.89, "source": "nuclear"}, {"Entity": "United States", "Year": 2001, "energy": 768.83, "source": "nuclear"}, {"Entity": "United States", "Year": 2002, "energy": 780.06, "source": "nuclear"}, {"Entity": "United States", "Year": 2003, "energy": 763.73, "source": "nuclear"}, {"Entity": "United States", "Year": 2004, "energy": 788.53, "source": "nuclear"}, {"Entity": "United States", "Year": 2005, "energy": 781.99, "source": "nuclear"}, {"Entity": "United States", "Year": 2006, "energy": 787.22, "source": "nuclear"}, {"Entity": "United States", "Year": 2007, "energy": 806.42, "source": "nuclear"}, {"Entity": "United States", "Year": 2008, "energy": 806.21, "source": "nuclear"}, {"Entity": "United States", "Year": 2009, "energy": 798.85, "source": "nuclear"}, {"Entity": "United States", "Year": 2010, "energy": 806.97, "source": "nuclear"}, {"Entity": "United States", "Year": 2011, "energy": 790.2, "source": "nuclear"}, {"Entity": "United States", "Year": 2012, "energy": 769.33, "source": "nuclear"}, {"Entity": "United States", "Year": 2013, "energy": 789.02, "source": "nuclear"}, {"Entity": "United States", "Year": 2014, "energy": 797.17, "source": "nuclear"}, {"Entity": "United States", "Year": 2015, "energy": 797.18, "source": "nuclear"}, {"Entity": "United States", "Year": 2016, "energy": 805.69, "source": "nuclear"}, {"Entity": "United States", "Year": 2017, "energy": 804.95, "source": "nuclear"}, {"Entity": "United States", "Year": 2018, "energy": 807.08, "source": "nuclear"}, {"Entity": "United States", "Year": 2019, "energy": 809.41, "source": "nuclear"}, {"Entity": "United States", "Year": 2020, "energy": 789.88, "source": "nuclear"}, {"Entity": "Australia", "Year": 2000, "energy": 17.11, "source": "renewables"}, {"Entity": "Australia", "Year": 2001, "energy": 17.4, "source": "renewables"}, {"Entity": "Australia", "Year": 2002, "energy": 17.35, "source": "renewables"}, {"Entity": "Australia", "Year": 2003, "energy": 18.5, "source": "renewables"}, {"Entity": "Australia", "Year": 2004, "energy": 19.41, "source": "renewables"}, {"Entity": "Australia", "Year": 2005, "energy": 19.75, "source": "renewables"}, {"Entity": "Australia", "Year": 2006, "energy": 21.19, "source": "renewables"}, {"Entity": "Australia", "Year": 2007, "energy": 20.93, "source": "renewables"}, {"Entity": "Australia", "Year": 2008, "energy": 18.49, "source": "renewables"}, {"Entity": "Australia", "Year": 2009, "energy": 18.32, "source": "renewables"}, {"Entity": "Australia", "Year": 2010, "energy": 21.13, "source": "renewables"}, {"Entity": "Australia", "Year": 2011, "energy": 27.33, "source": "renewables"}, {"Entity": "Australia", "Year": 2012, "energy": 26.63, "source": "renewables"}, {"Entity": "Australia", "Year": 2013, "energy": 34.2, "source": "renewables"}, {"Entity": "Australia", "Year": 2014, "energy": 36.15, "source": "renewables"}, {"Entity": "Australia", "Year": 2015, "energy": 33.12, "source": "renewables"}, {"Entity": "Australia", "Year": 2016, "energy": 38.41, "source": "renewables"}, {"Entity": "Australia", "Year": 2017, "energy": 40.77, "source": "renewables"}, {"Entity": "Australia", "Year": 2018, "energy": 42.93, "source": "renewables"}, {"Entity": "Australia", "Year": 2019, "energy": 53.41, "source": "renewables"}, {"Entity": "Australia", "Year": 2020, "energy": 63.99, "source": "renewables"}, {"Entity": "Brazil", "Year": 2000, "energy": 308.77, "source": "renewables"}, {"Entity": "Brazil", "Year": 2001, "energy": 273.71, "source": "renewables"}, {"Entity": "Brazil", "Year": 2002, "energy": 292.95, "source": "renewables"}, {"Entity": "Brazil", "Year": 2003, "energy": 313.88, "source": "renewables"}, {"Entity": "Brazil", "Year": 2004, "energy": 329.43, "source": "renewables"}, {"Entity": "Brazil", "Year": 2005, "energy": 346.96, "source": "renewables"}, {"Entity": "Brazil", "Year": 2006, "energy": 359.55, "source": "renewables"}, {"Entity": "Brazil", "Year": 2007, "energy": 387.88, "source": "renewables"}, {"Entity": "Brazil", "Year": 2008, "energy": 385.61, "source": "renewables"}, {"Entity": "Brazil", "Year": 2009, "energy": 410.13, "source": "renewables"}, {"Entity": "Brazil", "Year": 2010, "energy": 435.99, "source": "renewables"}, {"Entity": "Brazil", "Year": 2011, "energy": 462.32, "source": "renewables"}, {"Entity": "Brazil", "Year": 2012, "energy": 454.78, "source": "renewables"}, {"Entity": "Brazil", "Year": 2013, "energy": 436.84, "source": "renewables"}, {"Entity": "Brazil", "Year": 2014, "energy": 430.82, "source": "renewables"}, {"Entity": "Brazil", "Year": 2015, "energy": 428.81, "source": "renewables"}, {"Entity": "Brazil", "Year": 2016, "energy": 463.37, "source": "renewables"}, {"Entity": "Brazil", "Year": 2017, "energy": 464.4, "source": "renewables"}, {"Entity": "Brazil", "Year": 2018, "energy": 492.66, "source": "renewables"}, {"Entity": "Brazil", "Year": 2019, "energy": 512.59, "source": "renewables"}, {"Entity": "Brazil", "Year": 2020, "energy": 520.01, "source": "renewables"}, {"Entity": "Canada", "Year": 2000, "energy": 363.7, "source": "renewables"}, {"Entity": "Canada", "Year": 2001, "energy": 339.58, "source": "renewables"}, {"Entity": "Canada", "Year": 2002, "energy": 357.06, "source": "renewables"}, {"Entity": "Canada", "Year": 2003, "energy": 343.88, "source": "renewables"}, {"Entity": "Canada", "Year": 2004, "energy": 347.68, "source": "renewables"}, {"Entity": "Canada", "Year": 2005, "energy": 368.86, "source": "renewables"}, {"Entity": "Canada", "Year": 2006, "energy": 360.48, "source": "renewables"}, {"Entity": "Canada", "Year": 2007, "energy": 375.42, "source": "renewables"}, {"Entity": "Canada", "Year": 2008, "energy": 385.21, "source": "renewables"}, {"Entity": "Canada", "Year": 2009, "energy": 380.24, "source": "renewables"}, {"Entity": "Canada", "Year": 2010, "energy": 366.21, "source": "renewables"}, {"Entity": "Canada", "Year": 2011, "energy": 391.95, "source": "renewables"}, {"Entity": "Canada", "Year": 2012, "energy": 398.58, "source": "renewables"}, {"Entity": "Canada", "Year": 2013, "energy": 417.28, "source": "renewables"}, {"Entity": "Canada", "Year": 2014, "energy": 412.13, "source": "renewables"}, {"Entity": "Canada", "Year": 2015, "energy": 417.2, "source": "renewables"}, {"Entity": "Canada", "Year": 2016, "energy": 426.84, "source": "renewables"}, {"Entity": "Canada", "Year": 2017, "energy": 435.43, "source": "renewables"}, {"Entity": "Canada", "Year": 2018, "energy": 428.39, "source": "renewables"}, {"Entity": "Canada", "Year": 2019, "energy": 421.8, "source": "renewables"}, {"Entity": "Canada", "Year": 2020, "energy": 429.24, "source": "renewables"}, {"Entity": "China", "Year": 2000, "energy": 225.56, "source": "renewables"}, {"Entity": "China", "Year": 2001, "energy": 280.73, "source": "renewables"}, {"Entity": "China", "Year": 2002, "energy": 291.41, "source": "renewables"}, {"Entity": "China", "Year": 2003, "energy": 287.28, "source": "renewables"}, {"Entity": "China", "Year": 2004, "energy": 357.43, "source": "renewables"}, {"Entity": "China", "Year": 2005, "energy": 404.37, "source": "renewables"}, {"Entity": "China", "Year": 2006, "energy": 446.72, "source": "renewables"}, {"Entity": "China", "Year": 2007, "energy": 500.71, "source": "renewables"}, {"Entity": "China", "Year": 2008, "energy": 665.08, "source": "renewables"}, {"Entity": "China", "Year": 2009, "energy": 664.39, "source": "renewables"}, {"Entity": "China", "Year": 2010, "energy": 786.38, "source": "renewables"}, {"Entity": "China", "Year": 2011, "energy": 792.38, "source": "renewables"}, {"Entity": "China", "Year": 2012, "energy": 999.56, "source": "renewables"}, {"Entity": "China", "Year": 2013, "energy": 1093.37, "source": "renewables"}, {"Entity": "China", "Year": 2014, "energy": 1289.23, "source": "renewables"}, {"Entity": "China", "Year": 2015, "energy": 1393.66, "source": "renewables"}, {"Entity": "China", "Year": 2016, "energy": 1522.79, "source": "renewables"}, {"Entity": "China", "Year": 2017, "energy": 1667.06, "source": "renewables"}, {"Entity": "China", "Year": 2018, "energy": 1835.32, "source": "renewables"}, {"Entity": "China", "Year": 2019, "energy": 2014.57, "source": "renewables"}, {"Entity": "China", "Year": 2020, "energy": 2184.94, "source": "renewables"}, {"Entity": "France", "Year": 2000, "energy": 67.83, "source": "renewables"}, {"Entity": "France", "Year": 2001, "energy": 76.09, "source": "renewables"}, {"Entity": "France", "Year": 2002, "energy": 62.69, "source": "renewables"}, {"Entity": "France", "Year": 2003, "energy": 61.47, "source": "renewables"}, {"Entity": "France", "Year": 2004, "energy": 62.42, "source": "renewables"}, {"Entity": "France", "Year": 2005, "energy": 54.98, "source": "renewables"}, {"Entity": "France", "Year": 2006, "energy": 60.91, "source": "renewables"}, {"Entity": "France", "Year": 2007, "energy": 64.3, "source": "renewables"}, {"Entity": "France", "Year": 2008, "energy": 72.33, "source": "renewables"}, {"Entity": "France", "Year": 2009, "energy": 68.15, "source": "renewables"}, {"Entity": "France", "Year": 2010, "energy": 76.68, "source": "renewables"}, {"Entity": "France", "Year": 2011, "energy": 66.02, "source": "renewables"}, {"Entity": "France", "Year": 2012, "energy": 85.25, "source": "renewables"}, {"Entity": "France", "Year": 2013, "energy": 99.42, "source": "renewables"}, {"Entity": "France", "Year": 2014, "energy": 94.03, "source": "renewables"}, {"Entity": "France", "Year": 2015, "energy": 91.84, "source": "renewables"}, {"Entity": "France", "Year": 2016, "energy": 99, "source": "renewables"}, {"Entity": "France", "Year": 2017, "energy": 92.63, "source": "renewables"}, {"Entity": "France", "Year": 2018, "energy": 113.62, "source": "renewables"}, {"Entity": "France", "Year": 2019, "energy": 113.21, "source": "renewables"}, {"Entity": "France", "Year": 2020, "energy": 125.28, "source": "renewables"}, {"Entity": "Germany", "Year": 2000, "energy": 35.47, "source": "renewables"}, {"Entity": "Germany", "Year": 2001, "energy": 37.9, "source": "renewables"}, {"Entity": "Germany", "Year": 2002, "energy": 44.48, "source": "renewables"}, {"Entity": "Germany", "Year": 2003, "energy": 46.67, "source": "renewables"}, {"Entity": "Germany", "Year": 2004, "energy": 57.97, "source": "renewables"}, {"Entity": "Germany", "Year": 2005, "energy": 63.4, "source": "renewables"}, {"Entity": "Germany", "Year": 2006, "energy": 72.51, "source": "renewables"}, {"Entity": "Germany", "Year": 2007, "energy": 89.38, "source": "renewables"}, {"Entity": "Germany", "Year": 2008, "energy": 94.28, "source": "renewables"}, {"Entity": "Germany", "Year": 2009, "energy": 95.94, "source": "renewables"}, {"Entity": "Germany", "Year": 2010, "energy": 105.18, "source": "renewables"}, {"Entity": "Germany", "Year": 2011, "energy": 124.04, "source": "renewables"}, {"Entity": "Germany", "Year": 2012, "energy": 143.04, "source": "renewables"}, {"Entity": "Germany", "Year": 2013, "energy": 152.34, "source": "renewables"}, {"Entity": "Germany", "Year": 2014, "energy": 162.54, "source": "renewables"}, {"Entity": "Germany", "Year": 2015, "energy": 188.79, "source": "renewables"}, {"Entity": "Germany", "Year": 2016, "energy": 189.67, "source": "renewables"}, {"Entity": "Germany", "Year": 2017, "energy": 216.32, "source": "renewables"}, {"Entity": "Germany", "Year": 2018, "energy": 222.07, "source": "renewables"}, {"Entity": "Germany", "Year": 2019, "energy": 240.33, "source": "renewables"}, {"Entity": "Germany", "Year": 2020, "energy": 251.48, "source": "renewables"}, {"Entity": "India", "Year": 2000, "energy": 80.27, "source": "renewables"}, {"Entity": "India", "Year": 2001, "energy": 76.19, "source": "renewables"}, {"Entity": "India", "Year": 2002, "energy": 72.78, "source": "renewables"}, {"Entity": "India", "Year": 2003, "energy": 74.63, "source": "renewables"}, {"Entity": "India", "Year": 2004, "energy": 109.2, "source": "renewables"}, {"Entity": "India", "Year": 2005, "energy": 107.47, "source": "renewables"}, {"Entity": "India", "Year": 2006, "energy": 127.56, "source": "renewables"}, {"Entity": "India", "Year": 2007, "energy": 141.75, "source": "renewables"}, {"Entity": "India", "Year": 2008, "energy": 138.91, "source": "renewables"}, {"Entity": "India", "Year": 2009, "energy": 134.33, "source": "renewables"}, {"Entity": "India", "Year": 2010, "energy": 142.61, "source": "renewables"}, {"Entity": "India", "Year": 2011, "energy": 173.62, "source": "renewables"}, {"Entity": "India", "Year": 2012, "energy": 165.25, "source": "renewables"}, {"Entity": "India", "Year": 2013, "energy": 187.9, "source": "renewables"}, {"Entity": "India", "Year": 2014, "energy": 202.04, "source": "renewables"}, {"Entity": "India", "Year": 2015, "energy": 203.21, "source": "renewables"}, {"Entity": "India", "Year": 2016, "energy": 208.21, "source": "renewables"}, {"Entity": "India", "Year": 2017, "energy": 234.9, "source": "renewables"}, {"Entity": "India", "Year": 2018, "energy": 263.61, "source": "renewables"}, {"Entity": "India", "Year": 2019, "energy": 303.16, "source": "renewables"}, {"Entity": "India", "Year": 2020, "energy": 315.76, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2000, "energy": 19.6, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2001, "energy": 22.19, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2002, "energy": 21, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2003, "energy": 19.82, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2004, "energy": 20.97, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2005, "energy": 22.66, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2006, "energy": 21.18, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2007, "energy": 24.29, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2008, "energy": 26.34, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2009, "energy": 26.79, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2010, "energy": 34.63, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2011, "energy": 30.46, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2012, "energy": 31.11, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2013, "energy": 35.5, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2014, "energy": 34.41, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2015, "energy": 33.56, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2016, "energy": 39.58, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2017, "energy": 43.17, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2018, "energy": 48.38, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2019, "energy": 48.04, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2020, "energy": 52.91, "source": "renewables"}, {"Entity": "Italy", "Year": 2000, "energy": 50.87, "source": "renewables"}, {"Entity": "Italy", "Year": 2001, "energy": 54.35, "source": "renewables"}, {"Entity": "Italy", "Year": 2002, "energy": 48.31, "source": "renewables"}, {"Entity": "Italy", "Year": 2003, "energy": 46.86, "source": "renewables"}, {"Entity": "Italy", "Year": 2004, "energy": 53.88, "source": "renewables"}, {"Entity": "Italy", "Year": 2005, "energy": 48.43, "source": "renewables"}, {"Entity": "Italy", "Year": 2006, "energy": 50.64, "source": "renewables"}, {"Entity": "Italy", "Year": 2007, "energy": 47.72, "source": "renewables"}, {"Entity": "Italy", "Year": 2008, "energy": 58.16, "source": "renewables"}, {"Entity": "Italy", "Year": 2009, "energy": 69.26, "source": "renewables"}, {"Entity": "Italy", "Year": 2010, "energy": 76.98, "source": "renewables"}, {"Entity": "Italy", "Year": 2011, "energy": 82.96, "source": "renewables"}, {"Entity": "Italy", "Year": 2012, "energy": 92.22, "source": "renewables"}, {"Entity": "Italy", "Year": 2013, "energy": 112, "source": "renewables"}, {"Entity": "Italy", "Year": 2014, "energy": 120.68, "source": "renewables"}, {"Entity": "Italy", "Year": 2015, "energy": 108.89, "source": "renewables"}, {"Entity": "Italy", "Year": 2016, "energy": 108.01, "source": "renewables"}, {"Entity": "Italy", "Year": 2017, "energy": 103.89, "source": "renewables"}, {"Entity": "Italy", "Year": 2018, "energy": 114.41, "source": "renewables"}, {"Entity": "Italy", "Year": 2019, "energy": 115.83, "source": "renewables"}, {"Entity": "Italy", "Year": 2020, "energy": 116.9, "source": "renewables"}, {"Entity": "Japan", "Year": 2000, "energy": 104.16, "source": "renewables"}, {"Entity": "Japan", "Year": 2001, "energy": 101.36, "source": "renewables"}, {"Entity": "Japan", "Year": 2002, "energy": 101.1, "source": "renewables"}, {"Entity": "Japan", "Year": 2003, "energy": 114.18, "source": "renewables"}, {"Entity": "Japan", "Year": 2004, "energy": 114.73, "source": "renewables"}, {"Entity": "Japan", "Year": 2005, "energy": 100.57, "source": "renewables"}, {"Entity": "Japan", "Year": 2006, "energy": 112.07, "source": "renewables"}, {"Entity": "Japan", "Year": 2007, "energy": 100.8, "source": "renewables"}, {"Entity": "Japan", "Year": 2008, "energy": 100.79, "source": "renewables"}, {"Entity": "Japan", "Year": 2009, "energy": 102.28, "source": "renewables"}, {"Entity": "Japan", "Year": 2010, "energy": 113.92, "source": "renewables"}, {"Entity": "Japan", "Year": 2011, "energy": 116.5, "source": "renewables"}, {"Entity": "Japan", "Year": 2012, "energy": 111.09, "source": "renewables"}, {"Entity": "Japan", "Year": 2013, "energy": 121.48, "source": "renewables"}, {"Entity": "Japan", "Year": 2014, "energy": 136.53, "source": "renewables"}, {"Entity": "Japan", "Year": 2015, "energy": 157.34, "source": "renewables"}, {"Entity": "Japan", "Year": 2016, "energy": 157.7, "source": "renewables"}, {"Entity": "Japan", "Year": 2017, "energy": 175.12, "source": "renewables"}, {"Entity": "Japan", "Year": 2018, "energy": 183.63, "source": "renewables"}, {"Entity": "Japan", "Year": 2019, "energy": 192.72, "source": "renewables"}, {"Entity": "Japan", "Year": 2020, "energy": 205.6, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2000, "energy": 7.53, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2001, "energy": 8.08, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2002, "energy": 8.89, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2003, "energy": 8.62, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2004, "energy": 8.06, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2005, "energy": 7.86, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2006, "energy": 7.77, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2007, "energy": 8.17, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2008, "energy": 7.46, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2009, "energy": 6.88, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2010, "energy": 8.02, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2011, "energy": 7.88, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2012, "energy": 7.64, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2013, "energy": 7.73, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2014, "energy": 8.27, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2015, "energy": 9.45, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2016, "energy": 11.98, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2017, "energy": 11.64, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2018, "energy": 10.91, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2019, "energy": 11.09, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2020, "energy": 11.94, "source": "renewables"}, {"Entity": "Mexico", "Year": 2000, "energy": 44.51, "source": "renewables"}, {"Entity": "Mexico", "Year": 2001, "energy": 39.56, "source": "renewables"}, {"Entity": "Mexico", "Year": 2002, "energy": 35.67, "source": "renewables"}, {"Entity": "Mexico", "Year": 2003, "energy": 32.11, "source": "renewables"}, {"Entity": "Mexico", "Year": 2004, "energy": 38.19, "source": "renewables"}, {"Entity": "Mexico", "Year": 2005, "energy": 42.29, "source": "renewables"}, {"Entity": "Mexico", "Year": 2006, "energy": 43.63, "source": "renewables"}, {"Entity": "Mexico", "Year": 2007, "energy": 42.14, "source": "renewables"}, {"Entity": "Mexico", "Year": 2008, "energy": 53.22, "source": "renewables"}, {"Entity": "Mexico", "Year": 2009, "energy": 40.59, "source": "renewables"}, {"Entity": "Mexico", "Year": 2010, "energy": 51.37, "source": "renewables"}, {"Entity": "Mexico", "Year": 2011, "energy": 50.7, "source": "renewables"}, {"Entity": "Mexico", "Year": 2012, "energy": 47.2, "source": "renewables"}, {"Entity": "Mexico", "Year": 2013, "energy": 44.67, "source": "renewables"}, {"Entity": "Mexico", "Year": 2014, "energy": 57.46, "source": "renewables"}, {"Entity": "Mexico", "Year": 2015, "energy": 52.42, "source": "renewables"}, {"Entity": "Mexico", "Year": 2016, "energy": 52.97, "source": "renewables"}, {"Entity": "Mexico", "Year": 2017, "energy": 55.88, "source": "renewables"}, {"Entity": "Mexico", "Year": 2018, "energy": 58.78, "source": "renewables"}, {"Entity": "Mexico", "Year": 2019, "energy": 59, "source": "renewables"}, {"Entity": "Mexico", "Year": 2020, "energy": 69.19, "source": "renewables"}, {"Entity": "Poland", "Year": 2000, "energy": 2.33, "source": "renewables"}, {"Entity": "Poland", "Year": 2001, "energy": 2.78, "source": "renewables"}, {"Entity": "Poland", "Year": 2002, "energy": 2.77, "source": "renewables"}, {"Entity": "Poland", "Year": 2003, "energy": 2.25, "source": "renewables"}, {"Entity": "Poland", "Year": 2004, "energy": 3.2, "source": "renewables"}, {"Entity": "Poland", "Year": 2005, "energy": 3.85, "source": "renewables"}, {"Entity": "Poland", "Year": 2006, "energy": 4.29, "source": "renewables"}, {"Entity": "Poland", "Year": 2007, "energy": 5.43, "source": "renewables"}, {"Entity": "Poland", "Year": 2008, "energy": 6.61, "source": "renewables"}, {"Entity": "Poland", "Year": 2009, "energy": 8.69, "source": "renewables"}, {"Entity": "Poland", "Year": 2010, "energy": 10.88, "source": "renewables"}, {"Entity": "Poland", "Year": 2011, "energy": 13.13, "source": "renewables"}, {"Entity": "Poland", "Year": 2012, "energy": 16.88, "source": "renewables"}, {"Entity": "Poland", "Year": 2013, "energy": 17.06, "source": "renewables"}, {"Entity": "Poland", "Year": 2014, "energy": 19.85, "source": "renewables"}, {"Entity": "Poland", "Year": 2015, "energy": 22.69, "source": "renewables"}, {"Entity": "Poland", "Year": 2016, "energy": 22.81, "source": "renewables"}, {"Entity": "Poland", "Year": 2017, "energy": 24.13, "source": "renewables"}, {"Entity": "Poland", "Year": 2018, "energy": 21.62, "source": "renewables"}, {"Entity": "Poland", "Year": 2019, "energy": 25.46, "source": "renewables"}, {"Entity": "Poland", "Year": 2020, "energy": 28.23, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2000, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2001, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2002, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2003, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2004, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2005, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2006, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2007, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2008, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2009, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2010, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2011, "energy": 0.01, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2012, "energy": 0.03, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2013, "energy": 0.04, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2014, "energy": 0.05, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2015, "energy": 0.05, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2016, "energy": 0.05, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2017, "energy": 0.07, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2018, "energy": 0.16, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2019, "energy": 0.21, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2020, "energy": 0.21, "source": "renewables"}, {"Entity": "South Africa", "Year": 2000, "energy": 1.79, "source": "renewables"}, {"Entity": "South Africa", "Year": 2001, "energy": 2.46, "source": "renewables"}, {"Entity": "South Africa", "Year": 2002, "energy": 2.81, "source": "renewables"}, {"Entity": "South Africa", "Year": 2003, "energy": 1.19, "source": "renewables"}, {"Entity": "South Africa", "Year": 2004, "energy": 1.33, "source": "renewables"}, {"Entity": "South Africa", "Year": 2005, "energy": 1.75, "source": "renewables"}, {"Entity": "South Africa", "Year": 2006, "energy": 3.28, "source": "renewables"}, {"Entity": "South Africa", "Year": 2007, "energy": 1.3, "source": "renewables"}, {"Entity": "South Africa", "Year": 2008, "energy": 1.66, "source": "renewables"}, {"Entity": "South Africa", "Year": 2009, "energy": 1.86, "source": "renewables"}, {"Entity": "South Africa", "Year": 2010, "energy": 2.51, "source": "renewables"}, {"Entity": "South Africa", "Year": 2011, "energy": 2.49, "source": "renewables"}, {"Entity": "South Africa", "Year": 2012, "energy": 1.66, "source": "renewables"}, {"Entity": "South Africa", "Year": 2013, "energy": 1.62, "source": "renewables"}, {"Entity": "South Africa", "Year": 2014, "energy": 3.38, "source": "renewables"}, {"Entity": "South Africa", "Year": 2015, "energy": 6.09, "source": "renewables"}, {"Entity": "South Africa", "Year": 2016, "energy": 7.69, "source": "renewables"}, {"Entity": "South Africa", "Year": 2017, "energy": 10.04, "source": "renewables"}, {"Entity": "South Africa", "Year": 2018, "energy": 12.22, "source": "renewables"}, {"Entity": "South Africa", "Year": 2019, "energy": 12.57, "source": "renewables"}, {"Entity": "South Africa", "Year": 2020, "energy": 12.83, "source": "renewables"}, {"Entity": "Spain", "Year": 2000, "energy": 34.49, "source": "renewables"}, {"Entity": "Spain", "Year": 2001, "energy": 49.3, "source": "renewables"}, {"Entity": "Spain", "Year": 2002, "energy": 33.17, "source": "renewables"}, {"Entity": "Spain", "Year": 2003, "energy": 55.75, "source": "renewables"}, {"Entity": "Spain", "Year": 2004, "energy": 50.13, "source": "renewables"}, {"Entity": "Spain", "Year": 2005, "energy": 42.27, "source": "renewables"}, {"Entity": "Spain", "Year": 2006, "energy": 52.15, "source": "renewables"}, {"Entity": "Spain", "Year": 2007, "energy": 58.3, "source": "renewables"}, {"Entity": "Spain", "Year": 2008, "energy": 62.15, "source": "renewables"}, {"Entity": "Spain", "Year": 2009, "energy": 74.08, "source": "renewables"}, {"Entity": "Spain", "Year": 2010, "energy": 97.77, "source": "renewables"}, {"Entity": "Spain", "Year": 2011, "energy": 87.53, "source": "renewables"}, {"Entity": "Spain", "Year": 2012, "energy": 86.97, "source": "renewables"}, {"Entity": "Spain", "Year": 2013, "energy": 111.42, "source": "renewables"}, {"Entity": "Spain", "Year": 2014, "energy": 110.26, "source": "renewables"}, {"Entity": "Spain", "Year": 2015, "energy": 97.09, "source": "renewables"}, {"Entity": "Spain", "Year": 2016, "energy": 104.63, "source": "renewables"}, {"Entity": "Spain", "Year": 2017, "energy": 87.93, "source": "renewables"}, {"Entity": "Spain", "Year": 2018, "energy": 103.88, "source": "renewables"}, {"Entity": "Spain", "Year": 2019, "energy": 100.99, "source": "renewables"}, {"Entity": "Spain", "Year": 2020, "energy": 113.79, "source": "renewables"}, {"Entity": "Thailand", "Year": 2000, "energy": 6.38, "source": "renewables"}, {"Entity": "Thailand", "Year": 2001, "energy": 6.76, "source": "renewables"}, {"Entity": "Thailand", "Year": 2002, "energy": 8.07, "source": "renewables"}, {"Entity": "Thailand", "Year": 2003, "energy": 8.36, "source": "renewables"}, {"Entity": "Thailand", "Year": 2004, "energy": 7.63, "source": "renewables"}, {"Entity": "Thailand", "Year": 2005, "energy": 7.42, "source": "renewables"}, {"Entity": "Thailand", "Year": 2006, "energy": 9.82, "source": "renewables"}, {"Entity": "Thailand", "Year": 2007, "energy": 10.2, "source": "renewables"}, {"Entity": "Thailand", "Year": 2008, "energy": 8.95, "source": "renewables"}, {"Entity": "Thailand", "Year": 2009, "energy": 9.09, "source": "renewables"}, {"Entity": "Thailand", "Year": 2010, "energy": 8.58, "source": "renewables"}, {"Entity": "Thailand", "Year": 2011, "energy": 11.83, "source": "renewables"}, {"Entity": "Thailand", "Year": 2012, "energy": 13.42, "source": "renewables"}, {"Entity": "Thailand", "Year": 2013, "energy": 12.33, "source": "renewables"}, {"Entity": "Thailand", "Year": 2014, "energy": 13.68, "source": "renewables"}, {"Entity": "Thailand", "Year": 2015, "energy": 13.33, "source": "renewables"}, {"Entity": "Thailand", "Year": 2016, "energy": 15.97, "source": "renewables"}, {"Entity": "Thailand", "Year": 2017, "energy": 19.92, "source": "renewables"}, {"Entity": "Thailand", "Year": 2018, "energy": 25.84, "source": "renewables"}, {"Entity": "Thailand", "Year": 2019, "energy": 28.02, "source": "renewables"}, {"Entity": "Thailand", "Year": 2020, "energy": 24.73, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2000, "energy": 11.28, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2001, "energy": 12.05, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2002, "energy": 9.65, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2003, "energy": 9.27, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2004, "energy": 11.78, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2005, "energy": 12.4, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2006, "energy": 12.92, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2007, "energy": 10.47, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2008, "energy": 11.82, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2009, "energy": 12.12, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2010, "energy": 13.39, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2011, "energy": 11.2, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2012, "energy": 11.23, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2013, "energy": 15.11, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2014, "energy": 10.17, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2015, "energy": 7.1, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2016, "energy": 9.25, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2017, "energy": 10.88, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2018, "energy": 13.02, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2019, "energy": 11.87, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2020, "energy": 17.56, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2000, "energy": 9.98, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2001, "energy": 9.56, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2002, "energy": 11.13, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2003, "energy": 10.62, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2004, "energy": 14.14, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2005, "energy": 16.93, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2006, "energy": 18.11, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2007, "energy": 19.69, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2008, "energy": 21.85, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2009, "energy": 25.25, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2010, "energy": 26.18, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2011, "energy": 35.2, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2012, "energy": 41.24, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2013, "energy": 53.21, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2014, "energy": 64.52, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2015, "energy": 82.57, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2016, "energy": 82.99, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2017, "energy": 98.85, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2018, "energy": 110.03, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2019, "energy": 120.48, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2020, "energy": 131.74, "source": "renewables"}, {"Entity": "United States", "Year": 2000, "energy": 350.93, "source": "renewables"}, {"Entity": "United States", "Year": 2001, "energy": 280.06, "source": "renewables"}, {"Entity": "United States", "Year": 2002, "energy": 336.34, "source": "renewables"}, {"Entity": "United States", "Year": 2003, "energy": 349.18, "source": "renewables"}, {"Entity": "United States", "Year": 2004, "energy": 345.14, "source": "renewables"}, {"Entity": "United States", "Year": 2005, "energy": 353.04, "source": "renewables"}, {"Entity": "United States", "Year": 2006, "energy": 381.16, "source": "renewables"}, {"Entity": "United States", "Year": 2007, "energy": 347.91, "source": "renewables"}, {"Entity": "United States", "Year": 2008, "energy": 377.11, "source": "renewables"}, {"Entity": "United States", "Year": 2009, "energy": 415.56, "source": "renewables"}, {"Entity": "United States", "Year": 2010, "energy": 424.48, "source": "renewables"}, {"Entity": "United States", "Year": 2011, "energy": 509.74, "source": "renewables"}, {"Entity": "United States", "Year": 2012, "energy": 492.32, "source": "renewables"}, {"Entity": "United States", "Year": 2013, "energy": 520.38, "source": "renewables"}, {"Entity": "United States", "Year": 2014, "energy": 546.83, "source": "renewables"}, {"Entity": "United States", "Year": 2015, "energy": 556.49, "source": "renewables"}, {"Entity": "United States", "Year": 2016, "energy": 624.91, "source": "renewables"}, {"Entity": "United States", "Year": 2017, "energy": 707.19, "source": "renewables"}, {"Entity": "United States", "Year": 2018, "energy": 733.17, "source": "renewables"}, {"Entity": "United States", "Year": 2019, "energy": 760.76, "source": "renewables"}, {"Entity": "United States", "Year": 2020, "energy": 821.4, "source": "renewables"}], "metadata": {"Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}, "energy": {"type": "number", "semanticType": "Number"}, "source": {"type": "string", "semanticType": "String", "levels": ["fossil fuels", "nuclear", "renewables"]}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 158029.9988, 190729.9957, 209229.9957, ..., 6993180.176, 9861099.609, 9874660.156, 10096009.77\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 90.14, 91.79, 92.54, 804.95\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Transform the data into a long format where different energy sources (fossil fuels, nuclear, renewables) are unpivoted into separate rows. Each row should contain the year, entity (country), energy source type, and the corresponding energy value in TWh. This will enable visualization of energy generation trends over time by source and country.\",\n \"display_instruction\": \"Show **energy generation** trends by **source** and **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"source\", \"energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n },\n \"reason\": \"The user wants to visualize energy data across different sources with a line chart faceted by source. The original data has energy sources in separate columns (fossil fuels, nuclear, renewables), so we need to unpivot these columns into a long format with 'source' and 'energy' fields. The chart_encodings provided by the user are appropriate for this visualization goal, using faceting (column) to separate different energy sources.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "global-energy-20-small.csv", "resultTableId": "table-82", "chart": {"id": "chart-1760738394155", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"channel": "y", "bin": false, "fieldID": "concept-1760738385163"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {"channel": "column", "bin": false, "fieldID": "concept-1760738389404"}, "row": {"channel": "row", "bin": false}}, "tableRef": "global-energy-20-small.csv", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "", "displayContent": "Show **energy generation** trends by **source** and **Entity** over **Year**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code performs a data transformation to restructure the energy data from a wide format to a long format:\n\n1. **Unpivot energy columns**: Uses `pd.melt()` to transform the three energy source columns (**Electricity from fossil fuels**, **Electricity from nuclear**, and **Electricity from renewables**) from separate columns into rows, while keeping **Year** and **Entity** as identifier columns.\n\n2. **Create source classification**: Generates a new **source** column that captures which energy type each row represents, and stores the corresponding energy values in an **energy** column.\n\n3. **Clean source labels**: Removes the prefix \"Electricity from \" and suffix \" (TWh)\" from the source names, resulting in cleaner labels: **fossil fuels**, **nuclear**, and **renewables**.\n\n4. **Return restructured data**: The final dataset has each country-year-energy source combination as a separate row, making it easier to analyze and visualize energy mix across countries and time periods.", "concepts": [], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 190729.9957, 227580.0018, 233600.0061, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 90.14, 91.79, 92.54, nan\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code performs a data transformation to restructure the energy data from a wide format to a long format:\n\n1. **Unpivot energy columns**: Uses `pd.melt()` to transform the three energy source columns (**Electricity from fossil fuels**, **Electricity from nuclear**, and **Electricity from renewables**) from separate columns into rows, while keeping **Year** and **Entity** as identifier columns.\n\n2. **Create source classification**: Generates a new **source** column that captures which energy type each row represents, and stores the corresponding energy values in an **energy** column.\n\n3. **Clean source labels**: Removes the prefix \"Electricity from \" and suffix \" (TWh)\" from the source names, resulting in cleaner labels: **fossil fuels**, **nuclear**, and **renewables**.\n\n4. **Return restructured data**: The final dataset has each country-year-energy source combination as a separate row, making it easier to analyze and visualize energy mix across countries and time periods.\n\n[CONCEPTS EXPLANATION]\n\n```json\n[]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-45", "displayId": "renewable-energy", "names": ["Entity", "Year", "renewable_percentage"], "rows": [{"Entity": "Australia", "Year": 2000, "renewable_percentage": 8.6344368187}, {"Entity": "Australia", "Year": 2001, "renewable_percentage": 8.2180135078}, {"Entity": "Australia", "Year": 2002, "renewable_percentage": 8.0833022736}, {"Entity": "Australia", "Year": 2003, "renewable_percentage": 8.6598324205}, {"Entity": "Australia", "Year": 2004, "renewable_percentage": 8.7013045232}, {"Entity": "Australia", "Year": 2005, "renewable_percentage": 9.1562355123}, {"Entity": "Australia", "Year": 2006, "renewable_percentage": 9.6357600837}, {"Entity": "Australia", "Year": 2007, "renewable_percentage": 9.1190310213}, {"Entity": "Australia", "Year": 2008, "renewable_percentage": 8.0548900022}, {"Entity": "Australia", "Year": 2009, "renewable_percentage": 7.8043793133}, {"Entity": "Australia", "Year": 2010, "renewable_percentage": 9.0442152121}, {"Entity": "Australia", "Year": 2011, "renewable_percentage": 11.3454273735}, {"Entity": "Australia", "Year": 2012, "renewable_percentage": 11.4105750279}, {"Entity": "Australia", "Year": 2013, "renewable_percentage": 14.8708583355}, {"Entity": "Australia", "Year": 2014, "renewable_percentage": 14.9621290509}, {"Entity": "Australia", "Year": 2015, "renewable_percentage": 14.3476000693}, {"Entity": "Australia", "Year": 2016, "renewable_percentage": 15.6093794449}, {"Entity": "Australia", "Year": 2017, "renewable_percentage": 16.3138729943}, {"Entity": "Australia", "Year": 2018, "renewable_percentage": 17.145938174}, {"Entity": "Australia", "Year": 2019, "renewable_percentage": 21.3759705435}, {"Entity": "Australia", "Year": 2020, "renewable_percentage": 25.5031684668}, {"Entity": "Brazil", "Year": 2000, "renewable_percentage": 90.1307723743}, {"Entity": "Brazil", "Year": 2001, "renewable_percentage": 84.6953615744}, {"Entity": "Brazil", "Year": 2002, "renewable_percentage": 86.0883364189}, {"Entity": "Brazil", "Year": 2003, "renewable_percentage": 87.4561159097}, {"Entity": "Brazil", "Year": 2004, "renewable_percentage": 86.4260041451}, {"Entity": "Brazil", "Year": 2005, "renewable_percentage": 87.6781562721}, {"Entity": "Brazil", "Year": 2006, "renewable_percentage": 87.2842473236}, {"Entity": "Brazil", "Year": 2007, "renewable_percentage": 88.7252098726}, {"Entity": "Brazil", "Year": 2008, "renewable_percentage": 84.8072313004}, {"Entity": "Brazil", "Year": 2009, "renewable_percentage": 89.4172280725}, {"Entity": "Brazil", "Year": 2010, "renewable_percentage": 85.3576882415}, {"Entity": "Brazil", "Year": 2011, "renewable_percentage": 87.6618820986}, {"Entity": "Brazil", "Year": 2012, "renewable_percentage": 83.1164558813}, {"Entity": "Brazil", "Year": 2013, "renewable_percentage": 77.5240022006}, {"Entity": "Brazil", "Year": 2014, "renewable_percentage": 74.0418657409}, {"Entity": "Brazil", "Year": 2015, "renewable_percentage": 75.0231817625}, {"Entity": "Brazil", "Year": 2016, "renewable_percentage": 81.0938046902}, {"Entity": "Brazil", "Year": 2017, "renewable_percentage": 79.9091472228}, {"Entity": "Brazil", "Year": 2018, "renewable_percentage": 82.9198505403}, {"Entity": "Brazil", "Year": 2019, "renewable_percentage": 82.8548799017}, {"Entity": "Brazil", "Year": 2020, "renewable_percentage": 84.6411771408}, {"Entity": "Canada", "Year": 2000, "renewable_percentage": 61.8095917882}, {"Entity": "Canada", "Year": 2001, "renewable_percentage": 59.3287558747}, {"Entity": "Canada", "Year": 2002, "renewable_percentage": 61.1477403113}, {"Entity": "Canada", "Year": 2003, "renewable_percentage": 60.0789685174}, {"Entity": "Canada", "Year": 2004, "renewable_percentage": 59.6967771845}, {"Entity": "Canada", "Year": 2005, "renewable_percentage": 60.8208155391}, {"Entity": "Canada", "Year": 2006, "renewable_percentage": 60.8271602855}, {"Entity": "Canada", "Year": 2007, "renewable_percentage": 61.2460642446}, {"Entity": "Canada", "Year": 2008, "renewable_percentage": 62.6520720838}, {"Entity": "Canada", "Year": 2009, "renewable_percentage": 63.8919227732}, {"Entity": "Canada", "Year": 2010, "renewable_percentage": 62.9421470558}, {"Entity": "Canada", "Year": 2011, "renewable_percentage": 64.0922915917}, {"Entity": "Canada", "Year": 2012, "renewable_percentage": 65.098730952}, {"Entity": "Canada", "Year": 2013, "renewable_percentage": 65.4320794066}, {"Entity": "Canada", "Year": 2014, "renewable_percentage": 64.791145907}, {"Entity": "Canada", "Year": 2015, "renewable_percentage": 65.2946239925}, {"Entity": "Canada", "Year": 2016, "renewable_percentage": 66.1890584295}, {"Entity": "Canada", "Year": 2017, "renewable_percentage": 67.5399410579}, {"Entity": "Canada", "Year": 2018, "renewable_percentage": 67.3685700357}, {"Entity": "Canada", "Year": 2019, "renewable_percentage": 67.1741623137}, {"Entity": "Canada", "Year": 2020, "renewable_percentage": 68.7796436354}, {"Entity": "China", "Year": 2000, "renewable_percentage": 16.639126586}, {"Entity": "China", "Year": 2001, "renewable_percentage": 18.9581237042}, {"Entity": "China", "Year": 2002, "renewable_percentage": 17.6185006046}, {"Entity": "China", "Year": 2003, "renewable_percentage": 15.0362717081}, {"Entity": "China", "Year": 2004, "renewable_percentage": 16.2224108273}, {"Entity": "China", "Year": 2005, "renewable_percentage": 16.1731179957}, {"Entity": "China", "Year": 2006, "renewable_percentage": 15.5884036124}, {"Entity": "China", "Year": 2007, "renewable_percentage": 15.2583847828}, {"Entity": "China", "Year": 2008, "renewable_percentage": 19.0253335469}, {"Entity": "China", "Year": 2009, "renewable_percentage": 17.8857170547}, {"Entity": "China", "Year": 2010, "renewable_percentage": 18.7800759915}, {"Entity": "China", "Year": 2011, "renewable_percentage": 16.8902341543}, {"Entity": "China", "Year": 2012, "renewable_percentage": 20.122965176}, {"Entity": "China", "Year": 2013, "renewable_percentage": 20.2152481955}, {"Entity": "China", "Year": 2014, "renewable_percentage": 22.3502204285}, {"Entity": "China", "Year": 2015, "renewable_percentage": 24.079270189}, {"Entity": "China", "Year": 2016, "renewable_percentage": 25.0007798429}, {"Entity": "China", "Year": 2017, "renewable_percentage": 25.419242299}, {"Entity": "China", "Year": 2018, "renewable_percentage": 25.7747942589}, {"Entity": "China", "Year": 2019, "renewable_percentage": 26.9995671106}, {"Entity": "China", "Year": 2020, "renewable_percentage": 28.2464606924}, {"Entity": "France", "Year": 2000, "renewable_percentage": 12.7117691154}, {"Entity": "France", "Year": 2001, "renewable_percentage": 13.9961372206}, {"Entity": "France", "Year": 2002, "renewable_percentage": 11.3544157067}, {"Entity": "France", "Year": 2003, "renewable_percentage": 10.9783540506}, {"Entity": "France", "Year": 2004, "renewable_percentage": 11.0051305559}, {"Entity": "France", "Year": 2005, "renewable_percentage": 9.6479837153}, {"Entity": "France", "Year": 2006, "renewable_percentage": 10.7235915493}, {"Entity": "France", "Year": 2007, "renewable_percentage": 11.4370075239}, {"Entity": "France", "Year": 2008, "renewable_percentage": 12.7487441615}, {"Entity": "France", "Year": 2009, "renewable_percentage": 12.8776856068}, {"Entity": "France", "Year": 2010, "renewable_percentage": 13.6240072491}, {"Entity": "France", "Year": 2011, "renewable_percentage": 11.63553049}, {"Entity": "France", "Year": 2012, "renewable_percentage": 15.0331522889}, {"Entity": "France", "Year": 2013, "renewable_percentage": 17.2469424928}, {"Entity": "France", "Year": 2014, "renewable_percentage": 16.6074992494}, {"Entity": "France", "Year": 2015, "renewable_percentage": 16.002230276}, {"Entity": "France", "Year": 2016, "renewable_percentage": 17.7212924013}, {"Entity": "France", "Year": 2017, "renewable_percentage": 16.6576751547}, {"Entity": "France", "Year": 2018, "renewable_percentage": 19.7315179827}, {"Entity": "France", "Year": 2019, "renewable_percentage": 20.0116665488}, {"Entity": "France", "Year": 2020, "renewable_percentage": 23.7610241821}, {"Entity": "Germany", "Year": 2000, "renewable_percentage": 6.1977983575}, {"Entity": "Germany", "Year": 2001, "renewable_percentage": 6.5132585197}, {"Entity": "Germany", "Year": 2002, "renewable_percentage": 7.6431369854}, {"Entity": "Germany", "Year": 2003, "renewable_percentage": 7.7455438643}, {"Entity": "Germany", "Year": 2004, "renewable_percentage": 9.4989185292}, {"Entity": "Germany", "Year": 2005, "renewable_percentage": 10.3356645637}, {"Entity": "Germany", "Year": 2006, "renewable_percentage": 11.5129959829}, {"Entity": "Germany", "Year": 2007, "renewable_percentage": 14.135471525}, {"Entity": "Germany", "Year": 2008, "renewable_percentage": 14.8894504106}, {"Entity": "Germany", "Year": 2009, "renewable_percentage": 16.2902842395}, {"Entity": "Germany", "Year": 2010, "renewable_percentage": 16.8384989754}, {"Entity": "Germany", "Year": 2011, "renewable_percentage": 20.4967199299}, {"Entity": "Germany", "Year": 2012, "renewable_percentage": 23.056464482}, {"Entity": "Germany", "Year": 2013, "renewable_percentage": 24.1368929731}, {"Entity": "Germany", "Year": 2014, "renewable_percentage": 26.2182434067}, {"Entity": "Germany", "Year": 2015, "renewable_percentage": 29.4721888318}, {"Entity": "Germany", "Year": 2016, "renewable_percentage": 29.4990435013}, {"Entity": "Germany", "Year": 2017, "renewable_percentage": 33.4855497593}, {"Entity": "Germany", "Year": 2018, "renewable_percentage": 35.0976735365}, {"Entity": "Germany", "Year": 2019, "renewable_percentage": 40.0890757144}, {"Entity": "Germany", "Year": 2020, "renewable_percentage": 44.3324048937}, {"Entity": "India", "Year": 2000, "renewable_percentage": 14.0481982534}, {"Entity": "India", "Year": 2001, "renewable_percentage": 12.9997099422}, {"Entity": "India", "Year": 2002, "renewable_percentage": 11.938193032}, {"Entity": "India", "Year": 2003, "renewable_percentage": 11.695109147}, {"Entity": "India", "Year": 2004, "renewable_percentage": 15.6375300722}, {"Entity": "India", "Year": 2005, "renewable_percentage": 15.2543575768}, {"Entity": "India", "Year": 2006, "renewable_percentage": 17.1352578483}, {"Entity": "India", "Year": 2007, "renewable_percentage": 17.8019742295}, {"Entity": "India", "Year": 2008, "renewable_percentage": 16.768266921}, {"Entity": "India", "Year": 2009, "renewable_percentage": 15.269804822}, {"Entity": "India", "Year": 2010, "renewable_percentage": 15.2122201244}, {"Entity": "India", "Year": 2011, "renewable_percentage": 16.7911025145}, {"Entity": "India", "Year": 2012, "renewable_percentage": 15.1350014654}, {"Entity": "India", "Year": 2013, "renewable_percentage": 16.3941577818}, {"Entity": "India", "Year": 2014, "renewable_percentage": 16.0092550039}, {"Entity": "India", "Year": 2015, "renewable_percentage": 15.3718720687}, {"Entity": "India", "Year": 2016, "renewable_percentage": 14.8548475703}, {"Entity": "India", "Year": 2017, "renewable_percentage": 15.9669920335}, {"Entity": "India", "Year": 2018, "renewable_percentage": 16.6949549709}, {"Entity": "India", "Year": 2019, "renewable_percentage": 18.6915426873}, {"Entity": "India", "Year": 2020, "renewable_percentage": 20.2059243238}, {"Entity": "Indonesia", "Year": 2000, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2001, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2002, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2003, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2004, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2005, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2006, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2007, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2008, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2009, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2010, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2011, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2012, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2013, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2014, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2015, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2016, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2017, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2018, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2019, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2020, "renewable_percentage": null}, {"Entity": "Italy", "Year": 2000, "renewable_percentage": 18.900241501}, {"Entity": "Italy", "Year": 2001, "renewable_percentage": 20.049431902}, {"Entity": "Italy", "Year": 2002, "renewable_percentage": 17.4555571614}, {"Entity": "Italy", "Year": 2003, "renewable_percentage": 16.4202116476}, {"Entity": "Italy", "Year": 2004, "renewable_percentage": 18.2749380999}, {"Entity": "Italy", "Year": 2005, "renewable_percentage": 16.3769782226}, {"Entity": "Italy", "Year": 2006, "renewable_percentage": 16.5128639906}, {"Entity": "Italy", "Year": 2007, "renewable_percentage": 15.5333485238}, {"Entity": "Italy", "Year": 2008, "renewable_percentage": 18.6112}, {"Entity": "Italy", "Year": 2009, "renewable_percentage": 24.0837332221}, {"Entity": "Italy", "Year": 2010, "renewable_percentage": 25.8400187976}, {"Entity": "Italy", "Year": 2011, "renewable_percentage": 27.6773203443}, {"Entity": "Italy", "Year": 2012, "renewable_percentage": 31.1049649217}, {"Entity": "Italy", "Year": 2013, "renewable_percentage": 39.0148744209}, {"Entity": "Italy", "Year": 2014, "renewable_percentage": 43.4976931949}, {"Entity": "Italy", "Year": 2015, "renewable_percentage": 38.7577860829}, {"Entity": "Italy", "Year": 2016, "renewable_percentage": 37.6079387187}, {"Entity": "Italy", "Year": 2017, "renewable_percentage": 35.4174479255}, {"Entity": "Italy", "Year": 2018, "renewable_percentage": 39.8100142663}, {"Entity": "Italy", "Year": 2019, "renewable_percentage": 39.7563068474}, {"Entity": "Italy", "Year": 2020, "renewable_percentage": 42.0397741576}, {"Entity": "Japan", "Year": 2000, "renewable_percentage": 10.5382436261}, {"Entity": "Japan", "Year": 2001, "renewable_percentage": 10.447653504}, {"Entity": "Japan", "Year": 2002, "renewable_percentage": 10.2477294843}, {"Entity": "Japan", "Year": 2003, "renewable_percentage": 11.6993698448}, {"Entity": "Japan", "Year": 2004, "renewable_percentage": 11.4198974767}, {"Entity": "Japan", "Year": 2005, "renewable_percentage": 9.9068127192}, {"Entity": "Japan", "Year": 2006, "renewable_percentage": 10.8554989442}, {"Entity": "Japan", "Year": 2007, "renewable_percentage": 9.3897588285}, {"Entity": "Japan", "Year": 2008, "renewable_percentage": 10.0196834738}, {"Entity": "Japan", "Year": 2009, "renewable_percentage": 10.4667464874}, {"Entity": "Japan", "Year": 2010, "renewable_percentage": 10.5269966826}, {"Entity": "Japan", "Year": 2011, "renewable_percentage": 11.1272421632}, {"Entity": "Japan", "Year": 2012, "renewable_percentage": 10.6143703421}, {"Entity": "Japan", "Year": 2013, "renewable_percentage": 11.7965798852}, {"Entity": "Japan", "Year": 2014, "renewable_percentage": 13.2719619718}, {"Entity": "Japan", "Year": 2015, "renewable_percentage": 15.6586817408}, {"Entity": "Japan", "Year": 2016, "renewable_percentage": 15.6920107068}, {"Entity": "Japan", "Year": 2017, "renewable_percentage": 17.3559698312}, {"Entity": "Japan", "Year": 2018, "renewable_percentage": 18.144181175}, {"Entity": "Japan", "Year": 2019, "renewable_percentage": 19.4223288251}, {"Entity": "Japan", "Year": 2020, "renewable_percentage": 21.324925062}, {"Entity": "Kazakhstan", "Year": 2000, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2001, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2002, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2003, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2004, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2005, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2006, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2007, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2008, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2009, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2010, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2011, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2012, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2013, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2014, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2015, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2016, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2017, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2018, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2019, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2020, "renewable_percentage": null}, {"Entity": "Mexico", "Year": 2000, "renewable_percentage": 22.9291160107}, {"Entity": "Mexico", "Year": 2001, "renewable_percentage": 19.6649599841}, {"Entity": "Mexico", "Year": 2002, "renewable_percentage": 17.4220963173}, {"Entity": "Mexico", "Year": 2003, "renewable_percentage": 15.8536585366}, {"Entity": "Mexico", "Year": 2004, "renewable_percentage": 17.3134463687}, {"Entity": "Mexico", "Year": 2005, "renewable_percentage": 18.2780827246}, {"Entity": "Mexico", "Year": 2006, "renewable_percentage": 18.4256091896}, {"Entity": "Mexico", "Year": 2007, "renewable_percentage": 17.2761561168}, {"Entity": "Mexico", "Year": 2008, "renewable_percentage": 21.5387105913}, {"Entity": "Mexico", "Year": 2009, "renewable_percentage": 16.5369729069}, {"Entity": "Mexico", "Year": 2010, "renewable_percentage": 19.4281608109}, {"Entity": "Mexico", "Year": 2011, "renewable_percentage": 18.0916357408}, {"Entity": "Mexico", "Year": 2012, "renewable_percentage": 16.5759438104}, {"Entity": "Mexico", "Year": 2013, "renewable_percentage": 15.5492898914}, {"Entity": "Mexico", "Year": 2014, "renewable_percentage": 19.8008201523}, {"Entity": "Mexico", "Year": 2015, "renewable_percentage": 17.5976903451}, {"Entity": "Mexico", "Year": 2016, "renewable_percentage": 17.4806943436}, {"Entity": "Mexico", "Year": 2017, "renewable_percentage": 18.0759526428}, {"Entity": "Mexico", "Year": 2018, "renewable_percentage": 17.703752786}, {"Entity": "Mexico", "Year": 2019, "renewable_percentage": 18.5487927565}, {"Entity": "Mexico", "Year": 2020, "renewable_percentage": 21.2552224134}, {"Entity": "Poland", "Year": 2000, "renewable_percentage": 1.6273222517}, {"Entity": "Poland", "Year": 2001, "renewable_percentage": 1.934316727}, {"Entity": "Poland", "Year": 2002, "renewable_percentage": 1.9439960699}, {"Entity": "Poland", "Year": 2003, "renewable_percentage": 1.4999000067}, {"Entity": "Poland", "Year": 2004, "renewable_percentage": 2.1016681991}, {"Entity": "Poland", "Year": 2005, "renewable_percentage": 2.4830699774}, {"Entity": "Poland", "Year": 2006, "renewable_percentage": 2.673730134}, {"Entity": "Poland", "Year": 2007, "renewable_percentage": 3.4256513785}, {"Entity": "Poland", "Year": 2008, "renewable_percentage": 4.2744438696}, {"Entity": "Poland", "Year": 2009, "renewable_percentage": 5.7515388179}, {"Entity": "Poland", "Year": 2010, "renewable_percentage": 6.9299363057}, {"Entity": "Poland", "Year": 2011, "renewable_percentage": 8.0547205693}, {"Entity": "Poland", "Year": 2012, "renewable_percentage": 10.4436057663}, {"Entity": "Poland", "Year": 2013, "renewable_percentage": 10.4081508145}, {"Entity": "Poland", "Year": 2014, "renewable_percentage": 12.5331481248}, {"Entity": "Poland", "Year": 2015, "renewable_percentage": 13.8151485631}, {"Entity": "Poland", "Year": 2016, "renewable_percentage": 13.7335179722}, {"Entity": "Poland", "Year": 2017, "renewable_percentage": 14.1999646913}, {"Entity": "Poland", "Year": 2018, "renewable_percentage": 12.7559148032}, {"Entity": "Poland", "Year": 2019, "renewable_percentage": 15.6157998037}, {"Entity": "Poland", "Year": 2020, "renewable_percentage": 17.9648720886}, {"Entity": "Saudi Arabia", "Year": 2000, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2001, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2002, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2003, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2004, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2005, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2006, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2007, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2008, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2009, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2010, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2011, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2012, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2013, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2014, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2015, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2016, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2017, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2018, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2019, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2020, "renewable_percentage": null}, {"Entity": "South Africa", "Year": 2000, "renewable_percentage": 0.9110805721}, {"Entity": "South Africa", "Year": 2001, "renewable_percentage": 1.2516536074}, {"Entity": "South Africa", "Year": 2002, "renewable_percentage": 1.3802249619}, {"Entity": "South Africa", "Year": 2003, "renewable_percentage": 0.545271261}, {"Entity": "South Africa", "Year": 2004, "renewable_percentage": 0.5827199439}, {"Entity": "South Africa", "Year": 2005, "renewable_percentage": 0.763458686}, {"Entity": "South Africa", "Year": 2006, "renewable_percentage": 1.3863060017}, {"Entity": "South Africa", "Year": 2007, "renewable_percentage": 0.5267209594}, {"Entity": "South Africa", "Year": 2008, "renewable_percentage": 0.6895692269}, {"Entity": "South Africa", "Year": 2009, "renewable_percentage": 0.8031088083}, {"Entity": "South Africa", "Year": 2010, "renewable_percentage": 1.0330068318}, {"Entity": "South Africa", "Year": 2011, "renewable_percentage": 1.0184465622}, {"Entity": "South Africa", "Year": 2012, "renewable_percentage": 0.6890826069}, {"Entity": "South Africa", "Year": 2013, "renewable_percentage": 0.6792168043}, {"Entity": "South Africa", "Year": 2014, "renewable_percentage": 1.4288129861}, {"Entity": "South Africa", "Year": 2015, "renewable_percentage": 2.6256790549}, {"Entity": "South Africa", "Year": 2016, "renewable_percentage": 3.2586126531}, {"Entity": "South Africa", "Year": 2017, "renewable_percentage": 4.2202606137}, {"Entity": "South Africa", "Year": 2018, "renewable_percentage": 5.1554655529}, {"Entity": "South Africa", "Year": 2019, "renewable_percentage": 5.3589699864}, {"Entity": "South Africa", "Year": 2020, "renewable_percentage": 5.780581212}, {"Entity": "Spain", "Year": 2000, "renewable_percentage": 15.6119862394}, {"Entity": "Spain", "Year": 2001, "renewable_percentage": 21.1524434719}, {"Entity": "Spain", "Year": 2002, "renewable_percentage": 13.8260180901}, {"Entity": "Spain", "Year": 2003, "renewable_percentage": 21.667314419}, {"Entity": "Spain", "Year": 2004, "renewable_percentage": 18.3190206468}, {"Entity": "Spain", "Year": 2005, "renewable_percentage": 14.8597342333}, {"Entity": "Spain", "Year": 2006, "renewable_percentage": 17.6623992413}, {"Entity": "Spain", "Year": 2007, "renewable_percentage": 19.3347262296}, {"Entity": "Spain", "Year": 2008, "renewable_percentage": 20.0051501593}, {"Entity": "Spain", "Year": 2009, "renewable_percentage": 25.4107639008}, {"Entity": "Spain", "Year": 2010, "renewable_percentage": 32.7922186819}, {"Entity": "Spain", "Year": 2011, "renewable_percentage": 30.0408415417}, {"Entity": "Spain", "Year": 2012, "renewable_percentage": 29.6047928652}, {"Entity": "Spain", "Year": 2013, "renewable_percentage": 39.5850357054}, {"Entity": "Spain", "Year": 2014, "renewable_percentage": 40.1032952644}, {"Entity": "Spain", "Year": 2015, "renewable_percentage": 34.9899091826}, {"Entity": "Spain", "Year": 2016, "renewable_percentage": 38.5818061138}, {"Entity": "Spain", "Year": 2017, "renewable_percentage": 32.220593624}, {"Entity": "Spain", "Year": 2018, "renewable_percentage": 38.2080329557}, {"Entity": "Spain", "Year": 2019, "renewable_percentage": 37.280815091}, {"Entity": "Spain", "Year": 2020, "renewable_percentage": 43.8108805298}, {"Entity": "Thailand", "Year": 2000, "renewable_percentage": 7.1261029822}, {"Entity": "Thailand", "Year": 2001, "renewable_percentage": 7.061527212}, {"Entity": "Thailand", "Year": 2002, "renewable_percentage": 7.9444772593}, {"Entity": "Thailand", "Year": 2003, "renewable_percentage": 7.6718362852}, {"Entity": "Thailand", "Year": 2004, "renewable_percentage": 6.5163549406}, {"Entity": "Thailand", "Year": 2005, "renewable_percentage": 6.0325203252}, {"Entity": "Thailand", "Year": 2006, "renewable_percentage": 7.5988547551}, {"Entity": "Thailand", "Year": 2007, "renewable_percentage": 7.7085852479}, {"Entity": "Thailand", "Year": 2008, "renewable_percentage": 6.5625458278}, {"Entity": "Thailand", "Year": 2009, "renewable_percentage": 6.6263303689}, {"Entity": "Thailand", "Year": 2010, "renewable_percentage": 5.7085828343}, {"Entity": "Thailand", "Year": 2011, "renewable_percentage": 8.039961941}, {"Entity": "Thailand", "Year": 2012, "renewable_percentage": 8.5396118358}, {"Entity": "Thailand", "Year": 2013, "renewable_percentage": 7.6765035487}, {"Entity": "Thailand", "Year": 2014, "renewable_percentage": 8.395728489}, {"Entity": "Thailand", "Year": 2015, "renewable_percentage": 7.9949619145}, {"Entity": "Thailand", "Year": 2016, "renewable_percentage": 8.9840234023}, {"Entity": "Thailand", "Year": 2017, "renewable_percentage": 10.9570957096}, {"Entity": "Thailand", "Year": 2018, "renewable_percentage": 14.1900054915}, {"Entity": "Thailand", "Year": 2019, "renewable_percentage": 14.7001731284}, {"Entity": "Thailand", "Year": 2020, "renewable_percentage": 13.7963737796}, {"Entity": "Ukraine", "Year": 2000, "renewable_percentage": 6.5860921352}, {"Entity": "Ukraine", "Year": 2001, "renewable_percentage": 6.9729761009}, {"Entity": "Ukraine", "Year": 2002, "renewable_percentage": 5.5597165409}, {"Entity": "Ukraine", "Year": 2003, "renewable_percentage": 5.1442841287}, {"Entity": "Ukraine", "Year": 2004, "renewable_percentage": 6.4718162839}, {"Entity": "Ukraine", "Year": 2005, "renewable_percentage": 6.6698940347}, {"Entity": "Ukraine", "Year": 2006, "renewable_percentage": 6.68633235}, {"Entity": "Ukraine", "Year": 2007, "renewable_percentage": 5.3380238605}, {"Entity": "Ukraine", "Year": 2008, "renewable_percentage": 6.1377090041}, {"Entity": "Ukraine", "Year": 2009, "renewable_percentage": 6.980762585}, {"Entity": "Ukraine", "Year": 2010, "renewable_percentage": 7.0914098083}, {"Entity": "Ukraine", "Year": 2011, "renewable_percentage": 5.7450628366}, {"Entity": "Ukraine", "Year": 2012, "renewable_percentage": 5.6614236741}, {"Entity": "Ukraine", "Year": 2013, "renewable_percentage": 7.8003200661}, {"Entity": "Ukraine", "Year": 2014, "renewable_percentage": 5.5885262117}, {"Entity": "Ukraine", "Year": 2015, "renewable_percentage": 4.3924771096}, {"Entity": "Ukraine", "Year": 2016, "renewable_percentage": 5.6797249171}, {"Entity": "Ukraine", "Year": 2017, "renewable_percentage": 7.0457194664}, {"Entity": "Ukraine", "Year": 2018, "renewable_percentage": 8.228528092}, {"Entity": "Ukraine", "Year": 2019, "renewable_percentage": 7.7754487096}, {"Entity": "Ukraine", "Year": 2020, "renewable_percentage": 11.8440577364}, {"Entity": "United Kingdom", "Year": 2000, "renewable_percentage": 2.6657406913}, {"Entity": "United Kingdom", "Year": 2001, "renewable_percentage": 2.5001961451}, {"Entity": "United Kingdom", "Year": 2002, "renewable_percentage": 2.8939157566}, {"Entity": "United Kingdom", "Year": 2003, "renewable_percentage": 2.6854802003}, {"Entity": "United Kingdom", "Year": 2004, "renewable_percentage": 3.6136880575}, {"Entity": "United Kingdom", "Year": 2005, "renewable_percentage": 4.2815234434}, {"Entity": "United Kingdom", "Year": 2006, "renewable_percentage": 4.6029890199}, {"Entity": "United Kingdom", "Year": 2007, "renewable_percentage": 5.0104331009}, {"Entity": "United Kingdom", "Year": 2008, "renewable_percentage": 5.6776842324}, {"Entity": "United Kingdom", "Year": 2009, "renewable_percentage": 6.7679854187}, {"Entity": "United Kingdom", "Year": 2010, "renewable_percentage": 6.9092924441}, {"Entity": "United Kingdom", "Year": 2011, "renewable_percentage": 9.6422505889}, {"Entity": "United Kingdom", "Year": 2012, "renewable_percentage": 11.4273047189}, {"Entity": "United Kingdom", "Year": 2013, "renewable_percentage": 14.9727052732}, {"Entity": "United Kingdom", "Year": 2014, "renewable_percentage": 19.2476358104}, {"Entity": "United Kingdom", "Year": 2015, "renewable_percentage": 24.6227709191}, {"Entity": "United Kingdom", "Year": 2016, "renewable_percentage": 24.6788390627}, {"Entity": "United Kingdom", "Year": 2017, "renewable_percentage": 29.4986571173}, {"Entity": "United Kingdom", "Year": 2018, "renewable_percentage": 33.2919818457}, {"Entity": "United Kingdom", "Year": 2019, "renewable_percentage": 37.4568630499}, {"Entity": "United Kingdom", "Year": 2020, "renewable_percentage": 42.8603962651}, {"Entity": "United States", "Year": 2000, "renewable_percentage": 9.2298992662}, {"Entity": "United States", "Year": 2001, "renewable_percentage": 7.5132056541}, {"Entity": "United States", "Year": 2002, "renewable_percentage": 8.749216358}, {"Entity": "United States", "Year": 2003, "renewable_percentage": 9.0252110397}, {"Entity": "United States", "Year": 2004, "renewable_percentage": 8.7334100887}, {"Entity": "United States", "Year": 2005, "renewable_percentage": 8.7494640631}, {"Entity": "United States", "Year": 2006, "renewable_percentage": 9.4184742052}, {"Entity": "United States", "Year": 2007, "renewable_percentage": 8.3984096829}, {"Entity": "United States", "Year": 2008, "renewable_percentage": 9.180943292}, {"Entity": "United States", "Year": 2009, "renewable_percentage": 10.547689996}, {"Entity": "United States", "Year": 2010, "renewable_percentage": 10.3180892283}, {"Entity": "United States", "Year": 2011, "renewable_percentage": 12.4665249812}, {"Entity": "United States", "Year": 2012, "renewable_percentage": 12.1841179804}, {"Entity": "United States", "Year": 2013, "renewable_percentage": 12.8311154179}, {"Entity": "United States", "Year": 2014, "renewable_percentage": 13.3503092033}, {"Entity": "United States", "Year": 2015, "renewable_percentage": 13.6261352256}, {"Entity": "United States", "Year": 2016, "renewable_percentage": 15.2880936304}, {"Entity": "United States", "Year": 2017, "renewable_percentage": 17.4515276472}, {"Entity": "United States", "Year": 2018, "renewable_percentage": 17.4499886946}, {"Entity": "United States", "Year": 2019, "renewable_percentage": 18.2946243489}, {"Entity": "United States", "Year": 2020, "renewable_percentage": 20.3156921037}], "metadata": {"Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}, "renewable_percentage": {"type": "number", "semanticType": "Percentage"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage']].copy()\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 158029.9988, 190729.9957, 209229.9957, ..., 6993180.176, 9861099.609, 9874660.156, 10096009.77\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 90.14, 91.79, 92.54, 804.95\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Transform the data into a long format where different energy sources (fossil fuels, nuclear, renewables) are unpivoted into separate rows. Each row should contain the year, entity (country), energy source type, and the corresponding energy value in TWh. This will enable visualization of energy generation trends over time by source and country.\",\n \"display_instruction\": \"Show **energy generation** trends by **source** and **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"source\", \"energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n },\n \"reason\": \"The user wants to visualize energy data across different sources with a line chart faceted by source. The original data has energy sources in separate columns (fossil fuels, nuclear, renewables), so we need to unpivot these columns into a long format with 'source' and 'energy' fields. The chart_encodings provided by the user are appropriate for this visualization goal, using faceting (column) to separate different energy sources.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Year energy source\n0 Australia 2000 181.05 fossil fuels\n1 Australia 2001 194.33 fossil fuels\n2 Australia 2002 197.29 fossil fuels\n3 Australia 2003 195.13 fossil fuels\n4 Australia 2004 203.66 fossil fuels\n5 Australia 2005 195.95 fossil fuels\n6 Australia 2006 198.72 fossil fuels\n7 Australia 2007 208.59 fossil fuels\n8 Australia 2008 211.06 fossil fuels\n9 Australia 2009 216.42 fossil fuels\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show renewable percentage for each country\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage for each country and year. The renewable percentage is computed as the ratio of renewable energy to total energy (sum of fossil fuels, nuclear, and renewables) multiplied by 100. The output should contain year, entity (country), and the renewable percentage value.\",\n \"display_instruction\": \"Show **renewable percentage** for each **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"renewable_percentage\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"renewable_percentage\",\n \"color\": \"Entity\"\n },\n \"reason\": \"The user wants to see renewable percentage trends, which requires calculating the proportion of renewable energy relative to total energy generation. This is a single metric per country per year, so we don't need the 'column' faceting by source anymore. The chart_encodings are updated to reflect that we're now showing a percentage metric rather than absolute energy values by source.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage']].copy()\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-82", "resultTableId": "table-45", "chart": {"id": "chart-1760738416626", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-1760738385163"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {"fieldID": "concept-1760738389404", "sortBy": "[\"fossil fuels\",\"nuclear\",\"renewables\"]"}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-82", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "show renewable percentage for each country", "displayContent": "Show **renewable percentage** for each **Entity** over **Year**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code transforms global energy data to analyze renewable energy adoption:\n\n- Calculates **total_energy** by summing electricity generation from three sources: **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n- Computes **renewable_percentage** by dividing **Electricity from renewables (TWh)** by **total_energy** and multiplying by **100**\n- Handles edge cases by replacing infinite values (from division by zero) with **NaN**\n- Filters the dataset to retain only **Year**, **Entity** (country), and **renewable_percentage** columns", "concepts": [{"explanation": "The proportion of a country's total electricity generation that comes from renewable sources, expressed as a percentage. Calculated as: \\( \\frac{\\text{Electricity from renewables}}{\\text{Total electricity generation}} \\times 100 \\). This metric indicates the degree of renewable energy adoption in each country's energy mix.", "field": "renewable_percentage"}], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5738290.039, 9861099.609, 10502929.69, 10707219.73\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., nan, nan, nan, nan\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage']].copy()\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code transforms global energy data to analyze renewable energy adoption:\n\n- Calculates **total_energy** by summing electricity generation from three sources: **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n- Computes **renewable_percentage** by dividing **Electricity from renewables (TWh)** by **total_energy** and multiplying by **100**\n- Handles edge cases by replacing infinite values (from division by zero) with **NaN**\n- Filters the dataset to retain only **Year**, **Entity** (country), and **renewable_percentage** columns\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"renewable_percentage\",\n \"explanation\": \"The proportion of a country's total electricity generation that comes from renewable sources, expressed as a percentage. Calculated as: \\\\( \\\\frac{\\\\text{Electricity from renewables}}{\\\\text{Total electricity generation}} \\\\times 100 \\\\). This metric indicates the degree of renewable energy adoption in each country's energy mix.\"\n }\n]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-78", "displayId": "renewable-energy-rank", "names": ["Entity", "Year", "rank", "renewable_percentage"], "rows": [{"Entity": "Australia", "Year": 2000, "rank": 11, "renewable_percentage": 8.6344368187}, {"Entity": "Australia", "Year": 2001, "rank": 10, "renewable_percentage": 8.2180135078}, {"Entity": "Australia", "Year": 2002, "rank": 11, "renewable_percentage": 8.0833022736}, {"Entity": "Australia", "Year": 2003, "rank": 11, "renewable_percentage": 8.6598324205}, {"Entity": "Australia", "Year": 2004, "rank": 12, "renewable_percentage": 8.7013045232}, {"Entity": "Australia", "Year": 2005, "rank": 11, "renewable_percentage": 9.1562355123}, {"Entity": "Australia", "Year": 2006, "rank": 11, "renewable_percentage": 9.6357600837}, {"Entity": "Australia", "Year": 2007, "rank": 11, "renewable_percentage": 9.1190310213}, {"Entity": "Australia", "Year": 2008, "rank": 12, "renewable_percentage": 8.0548900022}, {"Entity": "Australia", "Year": 2009, "rank": 12, "renewable_percentage": 7.8043793133}, {"Entity": "Australia", "Year": 2010, "rank": 12, "renewable_percentage": 9.0442152121}, {"Entity": "Australia", "Year": 2011, "rank": 11, "renewable_percentage": 11.3454273735}, {"Entity": "Australia", "Year": 2012, "rank": 12, "renewable_percentage": 11.4105750279}, {"Entity": "Australia", "Year": 2013, "rank": 11, "renewable_percentage": 14.8708583355}, {"Entity": "Australia", "Year": 2014, "rank": 11, "renewable_percentage": 14.9621290509}, {"Entity": "Australia", "Year": 2015, "rank": 12, "renewable_percentage": 14.3476000693}, {"Entity": "Australia", "Year": 2016, "rank": 11, "renewable_percentage": 15.6093794449}, {"Entity": "Australia", "Year": 2017, "rank": 12, "renewable_percentage": 16.3138729943}, {"Entity": "Australia", "Year": 2018, "rank": 12, "renewable_percentage": 17.145938174}, {"Entity": "Australia", "Year": 2019, "rank": 8, "renewable_percentage": 21.3759705435}, {"Entity": "Australia", "Year": 2020, "rank": 8, "renewable_percentage": 25.5031684668}, {"Entity": "Brazil", "Year": 2000, "rank": 1, "renewable_percentage": 90.1307723743}, {"Entity": "Brazil", "Year": 2001, "rank": 1, "renewable_percentage": 84.6953615744}, {"Entity": "Brazil", "Year": 2002, "rank": 1, "renewable_percentage": 86.0883364189}, {"Entity": "Brazil", "Year": 2003, "rank": 1, "renewable_percentage": 87.4561159097}, {"Entity": "Brazil", "Year": 2004, "rank": 1, "renewable_percentage": 86.4260041451}, {"Entity": "Brazil", "Year": 2005, "rank": 1, "renewable_percentage": 87.6781562721}, {"Entity": "Brazil", "Year": 2006, "rank": 1, "renewable_percentage": 87.2842473236}, {"Entity": "Brazil", "Year": 2007, "rank": 1, "renewable_percentage": 88.7252098726}, {"Entity": "Brazil", "Year": 2008, "rank": 1, "renewable_percentage": 84.8072313004}, {"Entity": "Brazil", "Year": 2009, "rank": 1, "renewable_percentage": 89.4172280725}, {"Entity": "Brazil", "Year": 2010, "rank": 1, "renewable_percentage": 85.3576882415}, {"Entity": "Brazil", "Year": 2011, "rank": 1, "renewable_percentage": 87.6618820986}, {"Entity": "Brazil", "Year": 2012, "rank": 1, "renewable_percentage": 83.1164558813}, {"Entity": "Brazil", "Year": 2013, "rank": 1, "renewable_percentage": 77.5240022006}, {"Entity": "Brazil", "Year": 2014, "rank": 1, "renewable_percentage": 74.0418657409}, {"Entity": "Brazil", "Year": 2015, "rank": 1, "renewable_percentage": 75.0231817625}, {"Entity": "Brazil", "Year": 2016, "rank": 1, "renewable_percentage": 81.0938046902}, {"Entity": "Brazil", "Year": 2017, "rank": 1, "renewable_percentage": 79.9091472228}, {"Entity": "Brazil", "Year": 2018, "rank": 1, "renewable_percentage": 82.9198505403}, {"Entity": "Brazil", "Year": 2019, "rank": 1, "renewable_percentage": 82.8548799017}, {"Entity": "Brazil", "Year": 2020, "rank": 1, "renewable_percentage": 84.6411771408}, {"Entity": "Canada", "Year": 2000, "rank": 2, "renewable_percentage": 61.8095917882}, {"Entity": "Canada", "Year": 2001, "rank": 2, "renewable_percentage": 59.3287558747}, {"Entity": "Canada", "Year": 2002, "rank": 2, "renewable_percentage": 61.1477403113}, {"Entity": "Canada", "Year": 2003, "rank": 2, "renewable_percentage": 60.0789685174}, {"Entity": "Canada", "Year": 2004, "rank": 2, "renewable_percentage": 59.6967771845}, {"Entity": "Canada", "Year": 2005, "rank": 2, "renewable_percentage": 60.8208155391}, {"Entity": "Canada", "Year": 2006, "rank": 2, "renewable_percentage": 60.8271602855}, {"Entity": "Canada", "Year": 2007, "rank": 2, "renewable_percentage": 61.2460642446}, {"Entity": "Canada", "Year": 2008, "rank": 2, "renewable_percentage": 62.6520720838}, {"Entity": "Canada", "Year": 2009, "rank": 2, "renewable_percentage": 63.8919227732}, {"Entity": "Canada", "Year": 2010, "rank": 2, "renewable_percentage": 62.9421470558}, {"Entity": "Canada", "Year": 2011, "rank": 2, "renewable_percentage": 64.0922915917}, {"Entity": "Canada", "Year": 2012, "rank": 2, "renewable_percentage": 65.098730952}, {"Entity": "Canada", "Year": 2013, "rank": 2, "renewable_percentage": 65.4320794066}, {"Entity": "Canada", "Year": 2014, "rank": 2, "renewable_percentage": 64.791145907}, {"Entity": "Canada", "Year": 2015, "rank": 2, "renewable_percentage": 65.2946239925}, {"Entity": "Canada", "Year": 2016, "rank": 2, "renewable_percentage": 66.1890584295}, {"Entity": "Canada", "Year": 2017, "rank": 2, "renewable_percentage": 67.5399410579}, {"Entity": "Canada", "Year": 2018, "rank": 2, "renewable_percentage": 67.3685700357}, {"Entity": "Canada", "Year": 2019, "rank": 2, "renewable_percentage": 67.1741623137}, {"Entity": "Canada", "Year": 2020, "rank": 2, "renewable_percentage": 68.7796436354}, {"Entity": "China", "Year": 2000, "rank": 5, "renewable_percentage": 16.639126586}, {"Entity": "China", "Year": 2001, "rank": 6, "renewable_percentage": 18.9581237042}, {"Entity": "China", "Year": 2002, "rank": 3, "renewable_percentage": 17.6185006046}, {"Entity": "China", "Year": 2003, "rank": 6, "renewable_percentage": 15.0362717081}, {"Entity": "China", "Year": 2004, "rank": 6, "renewable_percentage": 16.2224108273}, {"Entity": "China", "Year": 2005, "rank": 5, "renewable_percentage": 16.1731179957}, {"Entity": "China", "Year": 2006, "rank": 7, "renewable_percentage": 15.5884036124}, {"Entity": "China", "Year": 2007, "rank": 7, "renewable_percentage": 15.2583847828}, {"Entity": "China", "Year": 2008, "rank": 5, "renewable_percentage": 19.0253335469}, {"Entity": "China", "Year": 2009, "rank": 5, "renewable_percentage": 17.8857170547}, {"Entity": "China", "Year": 2010, "rank": 6, "renewable_percentage": 18.7800759915}, {"Entity": "China", "Year": 2011, "rank": 7, "renewable_percentage": 16.8902341543}, {"Entity": "China", "Year": 2012, "rank": 6, "renewable_percentage": 20.122965176}, {"Entity": "China", "Year": 2013, "rank": 6, "renewable_percentage": 20.2152481955}, {"Entity": "China", "Year": 2014, "rank": 6, "renewable_percentage": 22.3502204285}, {"Entity": "China", "Year": 2015, "rank": 7, "renewable_percentage": 24.079270189}, {"Entity": "China", "Year": 2016, "rank": 6, "renewable_percentage": 25.0007798429}, {"Entity": "China", "Year": 2017, "rank": 7, "renewable_percentage": 25.419242299}, {"Entity": "China", "Year": 2018, "rank": 7, "renewable_percentage": 25.7747942589}, {"Entity": "China", "Year": 2019, "rank": 7, "renewable_percentage": 26.9995671106}, {"Entity": "China", "Year": 2020, "rank": 7, "renewable_percentage": 28.2464606924}, {"Entity": "France", "Year": 2000, "rank": 8, "renewable_percentage": 12.7117691154}, {"Entity": "France", "Year": 2001, "rank": 7, "renewable_percentage": 13.9961372206}, {"Entity": "France", "Year": 2002, "rank": 8, "renewable_percentage": 11.3544157067}, {"Entity": "France", "Year": 2003, "rank": 9, "renewable_percentage": 10.9783540506}, {"Entity": "France", "Year": 2004, "rank": 9, "renewable_percentage": 11.0051305559}, {"Entity": "France", "Year": 2005, "rank": 10, "renewable_percentage": 9.6479837153}, {"Entity": "France", "Year": 2006, "rank": 10, "renewable_percentage": 10.7235915493}, {"Entity": "France", "Year": 2007, "rank": 9, "renewable_percentage": 11.4370075239}, {"Entity": "France", "Year": 2008, "rank": 9, "renewable_percentage": 12.7487441615}, {"Entity": "France", "Year": 2009, "rank": 9, "renewable_percentage": 12.8776856068}, {"Entity": "France", "Year": 2010, "rank": 9, "renewable_percentage": 13.6240072491}, {"Entity": "France", "Year": 2011, "rank": 10, "renewable_percentage": 11.63553049}, {"Entity": "France", "Year": 2012, "rank": 9, "renewable_percentage": 15.0331522889}, {"Entity": "France", "Year": 2013, "rank": 7, "renewable_percentage": 17.2469424928}, {"Entity": "France", "Year": 2014, "rank": 9, "renewable_percentage": 16.6074992494}, {"Entity": "France", "Year": 2015, "rank": 9, "renewable_percentage": 16.002230276}, {"Entity": "France", "Year": 2016, "rank": 8, "renewable_percentage": 17.7212924013}, {"Entity": "France", "Year": 2017, "rank": 11, "renewable_percentage": 16.6576751547}, {"Entity": "France", "Year": 2018, "rank": 8, "renewable_percentage": 19.7315179827}, {"Entity": "France", "Year": 2019, "rank": 9, "renewable_percentage": 20.0116665488}, {"Entity": "France", "Year": 2020, "rank": 9, "renewable_percentage": 23.7610241821}, {"Entity": "Germany", "Year": 2000, "rank": 14, "renewable_percentage": 6.1977983575}, {"Entity": "Germany", "Year": 2001, "rank": 14, "renewable_percentage": 6.5132585197}, {"Entity": "Germany", "Year": 2002, "rank": 13, "renewable_percentage": 7.6431369854}, {"Entity": "Germany", "Year": 2003, "rank": 12, "renewable_percentage": 7.7455438643}, {"Entity": "Germany", "Year": 2004, "rank": 10, "renewable_percentage": 9.4989185292}, {"Entity": "Germany", "Year": 2005, "rank": 8, "renewable_percentage": 10.3356645637}, {"Entity": "Germany", "Year": 2006, "rank": 8, "renewable_percentage": 11.5129959829}, {"Entity": "Germany", "Year": 2007, "rank": 8, "renewable_percentage": 14.135471525}, {"Entity": "Germany", "Year": 2008, "rank": 8, "renewable_percentage": 14.8894504106}, {"Entity": "Germany", "Year": 2009, "rank": 7, "renewable_percentage": 16.2902842395}, {"Entity": "Germany", "Year": 2010, "rank": 7, "renewable_percentage": 16.8384989754}, {"Entity": "Germany", "Year": 2011, "rank": 5, "renewable_percentage": 20.4967199299}, {"Entity": "Germany", "Year": 2012, "rank": 5, "renewable_percentage": 23.056464482}, {"Entity": "Germany", "Year": 2013, "rank": 5, "renewable_percentage": 24.1368929731}, {"Entity": "Germany", "Year": 2014, "rank": 5, "renewable_percentage": 26.2182434067}, {"Entity": "Germany", "Year": 2015, "rank": 5, "renewable_percentage": 29.4721888318}, {"Entity": "Germany", "Year": 2016, "rank": 5, "renewable_percentage": 29.4990435013}, {"Entity": "Germany", "Year": 2017, "rank": 4, "renewable_percentage": 33.4855497593}, {"Entity": "Germany", "Year": 2018, "rank": 5, "renewable_percentage": 35.0976735365}, {"Entity": "Germany", "Year": 2019, "rank": 3, "renewable_percentage": 40.0890757144}, {"Entity": "Germany", "Year": 2020, "rank": 3, "renewable_percentage": 44.3324048937}, {"Entity": "India", "Year": 2000, "rank": 7, "renewable_percentage": 14.0481982534}, {"Entity": "India", "Year": 2001, "rank": 8, "renewable_percentage": 12.9997099422}, {"Entity": "India", "Year": 2002, "rank": 7, "renewable_percentage": 11.938193032}, {"Entity": "India", "Year": 2003, "rank": 8, "renewable_percentage": 11.695109147}, {"Entity": "India", "Year": 2004, "rank": 7, "renewable_percentage": 15.6375300722}, {"Entity": "India", "Year": 2005, "rank": 6, "renewable_percentage": 15.2543575768}, {"Entity": "India", "Year": 2006, "rank": 5, "renewable_percentage": 17.1352578483}, {"Entity": "India", "Year": 2007, "rank": 4, "renewable_percentage": 17.8019742295}, {"Entity": "India", "Year": 2008, "rank": 7, "renewable_percentage": 16.768266921}, {"Entity": "India", "Year": 2009, "rank": 8, "renewable_percentage": 15.269804822}, {"Entity": "India", "Year": 2010, "rank": 8, "renewable_percentage": 15.2122201244}, {"Entity": "India", "Year": 2011, "rank": 8, "renewable_percentage": 16.7911025145}, {"Entity": "India", "Year": 2012, "rank": 8, "renewable_percentage": 15.1350014654}, {"Entity": "India", "Year": 2013, "rank": 8, "renewable_percentage": 16.3941577818}, {"Entity": "India", "Year": 2014, "rank": 10, "renewable_percentage": 16.0092550039}, {"Entity": "India", "Year": 2015, "rank": 11, "renewable_percentage": 15.3718720687}, {"Entity": "India", "Year": 2016, "rank": 13, "renewable_percentage": 14.8548475703}, {"Entity": "India", "Year": 2017, "rank": 13, "renewable_percentage": 15.9669920335}, {"Entity": "India", "Year": 2018, "rank": 13, "renewable_percentage": 16.6949549709}, {"Entity": "India", "Year": 2019, "rank": 11, "renewable_percentage": 18.6915426873}, {"Entity": "India", "Year": 2020, "rank": 13, "renewable_percentage": 20.2059243238}, {"Entity": "Indonesia", "Year": 2000, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2001, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2002, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2003, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2004, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2005, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2006, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2007, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2008, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2009, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2010, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2011, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2012, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2013, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2014, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2015, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2016, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2017, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2018, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2019, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2020, "rank": null, "renewable_percentage": null}, {"Entity": "Italy", "Year": 2000, "rank": 4, "renewable_percentage": 18.900241501}, {"Entity": "Italy", "Year": 2001, "rank": 4, "renewable_percentage": 20.049431902}, {"Entity": "Italy", "Year": 2002, "rank": 4, "renewable_percentage": 17.4555571614}, {"Entity": "Italy", "Year": 2003, "rank": 4, "renewable_percentage": 16.4202116476}, {"Entity": "Italy", "Year": 2004, "rank": 4, "renewable_percentage": 18.2749380999}, {"Entity": "Italy", "Year": 2005, "rank": 4, "renewable_percentage": 16.3769782226}, {"Entity": "Italy", "Year": 2006, "rank": 6, "renewable_percentage": 16.5128639906}, {"Entity": "Italy", "Year": 2007, "rank": 6, "renewable_percentage": 15.5333485238}, {"Entity": "Italy", "Year": 2008, "rank": 6, "renewable_percentage": 18.6112}, {"Entity": "Italy", "Year": 2009, "rank": 4, "renewable_percentage": 24.0837332221}, {"Entity": "Italy", "Year": 2010, "rank": 4, "renewable_percentage": 25.8400187976}, {"Entity": "Italy", "Year": 2011, "rank": 4, "renewable_percentage": 27.6773203443}, {"Entity": "Italy", "Year": 2012, "rank": 3, "renewable_percentage": 31.1049649217}, {"Entity": "Italy", "Year": 2013, "rank": 4, "renewable_percentage": 39.0148744209}, {"Entity": "Italy", "Year": 2014, "rank": 3, "renewable_percentage": 43.4976931949}, {"Entity": "Italy", "Year": 2015, "rank": 3, "renewable_percentage": 38.7577860829}, {"Entity": "Italy", "Year": 2016, "rank": 4, "renewable_percentage": 37.6079387187}, {"Entity": "Italy", "Year": 2017, "rank": 3, "renewable_percentage": 35.4174479255}, {"Entity": "Italy", "Year": 2018, "rank": 3, "renewable_percentage": 39.8100142663}, {"Entity": "Italy", "Year": 2019, "rank": 4, "renewable_percentage": 39.7563068474}, {"Entity": "Italy", "Year": 2020, "rank": 6, "renewable_percentage": 42.0397741576}, {"Entity": "Japan", "Year": 2000, "rank": 9, "renewable_percentage": 10.5382436261}, {"Entity": "Japan", "Year": 2001, "rank": 9, "renewable_percentage": 10.447653504}, {"Entity": "Japan", "Year": 2002, "rank": 9, "renewable_percentage": 10.2477294843}, {"Entity": "Japan", "Year": 2003, "rank": 7, "renewable_percentage": 11.6993698448}, {"Entity": "Japan", "Year": 2004, "rank": 8, "renewable_percentage": 11.4198974767}, {"Entity": "Japan", "Year": 2005, "rank": 9, "renewable_percentage": 9.9068127192}, {"Entity": "Japan", "Year": 2006, "rank": 9, "renewable_percentage": 10.8554989442}, {"Entity": "Japan", "Year": 2007, "rank": 10, "renewable_percentage": 9.3897588285}, {"Entity": "Japan", "Year": 2008, "rank": 10, "renewable_percentage": 10.0196834738}, {"Entity": "Japan", "Year": 2009, "rank": 11, "renewable_percentage": 10.4667464874}, {"Entity": "Japan", "Year": 2010, "rank": 10, "renewable_percentage": 10.5269966826}, {"Entity": "Japan", "Year": 2011, "rank": 12, "renewable_percentage": 11.1272421632}, {"Entity": "Japan", "Year": 2012, "rank": 13, "renewable_percentage": 10.6143703421}, {"Entity": "Japan", "Year": 2013, "rank": 13, "renewable_percentage": 11.7965798852}, {"Entity": "Japan", "Year": 2014, "rank": 13, "renewable_percentage": 13.2719619718}, {"Entity": "Japan", "Year": 2015, "rank": 10, "renewable_percentage": 15.6586817408}, {"Entity": "Japan", "Year": 2016, "rank": 10, "renewable_percentage": 15.6920107068}, {"Entity": "Japan", "Year": 2017, "rank": 10, "renewable_percentage": 17.3559698312}, {"Entity": "Japan", "Year": 2018, "rank": 9, "renewable_percentage": 18.144181175}, {"Entity": "Japan", "Year": 2019, "rank": 10, "renewable_percentage": 19.4223288251}, {"Entity": "Japan", "Year": 2020, "rank": 10, "renewable_percentage": 21.324925062}, {"Entity": "Kazakhstan", "Year": 2000, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2001, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2002, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2003, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2004, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2005, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2006, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2007, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2008, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2009, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2010, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2011, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2012, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2013, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2014, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2015, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2016, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2017, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2018, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2019, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2020, "rank": null, "renewable_percentage": null}, {"Entity": "Mexico", "Year": 2000, "rank": 3, "renewable_percentage": 22.9291160107}, {"Entity": "Mexico", "Year": 2001, "rank": 5, "renewable_percentage": 19.6649599841}, {"Entity": "Mexico", "Year": 2002, "rank": 5, "renewable_percentage": 17.4220963173}, {"Entity": "Mexico", "Year": 2003, "rank": 5, "renewable_percentage": 15.8536585366}, {"Entity": "Mexico", "Year": 2004, "rank": 5, "renewable_percentage": 17.3134463687}, {"Entity": "Mexico", "Year": 2005, "rank": 3, "renewable_percentage": 18.2780827246}, {"Entity": "Mexico", "Year": 2006, "rank": 3, "renewable_percentage": 18.4256091896}, {"Entity": "Mexico", "Year": 2007, "rank": 5, "renewable_percentage": 17.2761561168}, {"Entity": "Mexico", "Year": 2008, "rank": 3, "renewable_percentage": 21.5387105913}, {"Entity": "Mexico", "Year": 2009, "rank": 6, "renewable_percentage": 16.5369729069}, {"Entity": "Mexico", "Year": 2010, "rank": 5, "renewable_percentage": 19.4281608109}, {"Entity": "Mexico", "Year": 2011, "rank": 6, "renewable_percentage": 18.0916357408}, {"Entity": "Mexico", "Year": 2012, "rank": 7, "renewable_percentage": 16.5759438104}, {"Entity": "Mexico", "Year": 2013, "rank": 9, "renewable_percentage": 15.5492898914}, {"Entity": "Mexico", "Year": 2014, "rank": 7, "renewable_percentage": 19.8008201523}, {"Entity": "Mexico", "Year": 2015, "rank": 8, "renewable_percentage": 17.5976903451}, {"Entity": "Mexico", "Year": 2016, "rank": 9, "renewable_percentage": 17.4806943436}, {"Entity": "Mexico", "Year": 2017, "rank": 8, "renewable_percentage": 18.0759526428}, {"Entity": "Mexico", "Year": 2018, "rank": 10, "renewable_percentage": 17.703752786}, {"Entity": "Mexico", "Year": 2019, "rank": 12, "renewable_percentage": 18.5487927565}, {"Entity": "Mexico", "Year": 2020, "rank": 11, "renewable_percentage": 21.2552224134}, {"Entity": "Poland", "Year": 2000, "rank": 16, "renewable_percentage": 1.6273222517}, {"Entity": "Poland", "Year": 2001, "rank": 16, "renewable_percentage": 1.934316727}, {"Entity": "Poland", "Year": 2002, "rank": 16, "renewable_percentage": 1.9439960699}, {"Entity": "Poland", "Year": 2003, "rank": 16, "renewable_percentage": 1.4999000067}, {"Entity": "Poland", "Year": 2004, "rank": 16, "renewable_percentage": 2.1016681991}, {"Entity": "Poland", "Year": 2005, "rank": 16, "renewable_percentage": 2.4830699774}, {"Entity": "Poland", "Year": 2006, "rank": 16, "renewable_percentage": 2.673730134}, {"Entity": "Poland", "Year": 2007, "rank": 16, "renewable_percentage": 3.4256513785}, {"Entity": "Poland", "Year": 2008, "rank": 16, "renewable_percentage": 4.2744438696}, {"Entity": "Poland", "Year": 2009, "rank": 16, "renewable_percentage": 5.7515388179}, {"Entity": "Poland", "Year": 2010, "rank": 14, "renewable_percentage": 6.9299363057}, {"Entity": "Poland", "Year": 2011, "rank": 14, "renewable_percentage": 8.0547205693}, {"Entity": "Poland", "Year": 2012, "rank": 14, "renewable_percentage": 10.4436057663}, {"Entity": "Poland", "Year": 2013, "rank": 14, "renewable_percentage": 10.4081508145}, {"Entity": "Poland", "Year": 2014, "rank": 14, "renewable_percentage": 12.5331481248}, {"Entity": "Poland", "Year": 2015, "rank": 13, "renewable_percentage": 13.8151485631}, {"Entity": "Poland", "Year": 2016, "rank": 14, "renewable_percentage": 13.7335179722}, {"Entity": "Poland", "Year": 2017, "rank": 14, "renewable_percentage": 14.1999646913}, {"Entity": "Poland", "Year": 2018, "rank": 15, "renewable_percentage": 12.7559148032}, {"Entity": "Poland", "Year": 2019, "rank": 14, "renewable_percentage": 15.6157998037}, {"Entity": "Poland", "Year": 2020, "rank": 14, "renewable_percentage": 17.9648720886}, {"Entity": "Saudi Arabia", "Year": 2000, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2001, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2002, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2003, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2004, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2005, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2006, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2007, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2008, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2009, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2010, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2011, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2012, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2013, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2014, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2015, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2016, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2017, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2018, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2019, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2020, "rank": null, "renewable_percentage": null}, {"Entity": "South Africa", "Year": 2000, "rank": 17, "renewable_percentage": 0.9110805721}, {"Entity": "South Africa", "Year": 2001, "rank": 17, "renewable_percentage": 1.2516536074}, {"Entity": "South Africa", "Year": 2002, "rank": 17, "renewable_percentage": 1.3802249619}, {"Entity": "South Africa", "Year": 2003, "rank": 17, "renewable_percentage": 0.545271261}, {"Entity": "South Africa", "Year": 2004, "rank": 17, "renewable_percentage": 0.5827199439}, {"Entity": "South Africa", "Year": 2005, "rank": 17, "renewable_percentage": 0.763458686}, {"Entity": "South Africa", "Year": 2006, "rank": 17, "renewable_percentage": 1.3863060017}, {"Entity": "South Africa", "Year": 2007, "rank": 17, "renewable_percentage": 0.5267209594}, {"Entity": "South Africa", "Year": 2008, "rank": 17, "renewable_percentage": 0.6895692269}, {"Entity": "South Africa", "Year": 2009, "rank": 17, "renewable_percentage": 0.8031088083}, {"Entity": "South Africa", "Year": 2010, "rank": 17, "renewable_percentage": 1.0330068318}, {"Entity": "South Africa", "Year": 2011, "rank": 17, "renewable_percentage": 1.0184465622}, {"Entity": "South Africa", "Year": 2012, "rank": 17, "renewable_percentage": 0.6890826069}, {"Entity": "South Africa", "Year": 2013, "rank": 17, "renewable_percentage": 0.6792168043}, {"Entity": "South Africa", "Year": 2014, "rank": 17, "renewable_percentage": 1.4288129861}, {"Entity": "South Africa", "Year": 2015, "rank": 17, "renewable_percentage": 2.6256790549}, {"Entity": "South Africa", "Year": 2016, "rank": 17, "renewable_percentage": 3.2586126531}, {"Entity": "South Africa", "Year": 2017, "rank": 17, "renewable_percentage": 4.2202606137}, {"Entity": "South Africa", "Year": 2018, "rank": 17, "renewable_percentage": 5.1554655529}, {"Entity": "South Africa", "Year": 2019, "rank": 17, "renewable_percentage": 5.3589699864}, {"Entity": "South Africa", "Year": 2020, "rank": 17, "renewable_percentage": 5.780581212}, {"Entity": "Spain", "Year": 2000, "rank": 6, "renewable_percentage": 15.6119862394}, {"Entity": "Spain", "Year": 2001, "rank": 3, "renewable_percentage": 21.1524434719}, {"Entity": "Spain", "Year": 2002, "rank": 6, "renewable_percentage": 13.8260180901}, {"Entity": "Spain", "Year": 2003, "rank": 3, "renewable_percentage": 21.667314419}, {"Entity": "Spain", "Year": 2004, "rank": 3, "renewable_percentage": 18.3190206468}, {"Entity": "Spain", "Year": 2005, "rank": 7, "renewable_percentage": 14.8597342333}, {"Entity": "Spain", "Year": 2006, "rank": 4, "renewable_percentage": 17.6623992413}, {"Entity": "Spain", "Year": 2007, "rank": 3, "renewable_percentage": 19.3347262296}, {"Entity": "Spain", "Year": 2008, "rank": 4, "renewable_percentage": 20.0051501593}, {"Entity": "Spain", "Year": 2009, "rank": 3, "renewable_percentage": 25.4107639008}, {"Entity": "Spain", "Year": 2010, "rank": 3, "renewable_percentage": 32.7922186819}, {"Entity": "Spain", "Year": 2011, "rank": 3, "renewable_percentage": 30.0408415417}, {"Entity": "Spain", "Year": 2012, "rank": 4, "renewable_percentage": 29.6047928652}, {"Entity": "Spain", "Year": 2013, "rank": 3, "renewable_percentage": 39.5850357054}, {"Entity": "Spain", "Year": 2014, "rank": 4, "renewable_percentage": 40.1032952644}, {"Entity": "Spain", "Year": 2015, "rank": 4, "renewable_percentage": 34.9899091826}, {"Entity": "Spain", "Year": 2016, "rank": 3, "renewable_percentage": 38.5818061138}, {"Entity": "Spain", "Year": 2017, "rank": 5, "renewable_percentage": 32.220593624}, {"Entity": "Spain", "Year": 2018, "rank": 4, "renewable_percentage": 38.2080329557}, {"Entity": "Spain", "Year": 2019, "rank": 6, "renewable_percentage": 37.280815091}, {"Entity": "Spain", "Year": 2020, "rank": 4, "renewable_percentage": 43.8108805298}, {"Entity": "Thailand", "Year": 2000, "rank": 12, "renewable_percentage": 7.1261029822}, {"Entity": "Thailand", "Year": 2001, "rank": 12, "renewable_percentage": 7.061527212}, {"Entity": "Thailand", "Year": 2002, "rank": 12, "renewable_percentage": 7.9444772593}, {"Entity": "Thailand", "Year": 2003, "rank": 13, "renewable_percentage": 7.6718362852}, {"Entity": "Thailand", "Year": 2004, "rank": 13, "renewable_percentage": 6.5163549406}, {"Entity": "Thailand", "Year": 2005, "rank": 14, "renewable_percentage": 6.0325203252}, {"Entity": "Thailand", "Year": 2006, "rank": 13, "renewable_percentage": 7.5988547551}, {"Entity": "Thailand", "Year": 2007, "rank": 13, "renewable_percentage": 7.7085852479}, {"Entity": "Thailand", "Year": 2008, "rank": 13, "renewable_percentage": 6.5625458278}, {"Entity": "Thailand", "Year": 2009, "rank": 15, "renewable_percentage": 6.6263303689}, {"Entity": "Thailand", "Year": 2010, "rank": 16, "renewable_percentage": 5.7085828343}, {"Entity": "Thailand", "Year": 2011, "rank": 15, "renewable_percentage": 8.039961941}, {"Entity": "Thailand", "Year": 2012, "rank": 15, "renewable_percentage": 8.5396118358}, {"Entity": "Thailand", "Year": 2013, "rank": 16, "renewable_percentage": 7.6765035487}, {"Entity": "Thailand", "Year": 2014, "rank": 15, "renewable_percentage": 8.395728489}, {"Entity": "Thailand", "Year": 2015, "rank": 15, "renewable_percentage": 7.9949619145}, {"Entity": "Thailand", "Year": 2016, "rank": 15, "renewable_percentage": 8.9840234023}, {"Entity": "Thailand", "Year": 2017, "rank": 15, "renewable_percentage": 10.9570957096}, {"Entity": "Thailand", "Year": 2018, "rank": 14, "renewable_percentage": 14.1900054915}, {"Entity": "Thailand", "Year": 2019, "rank": 15, "renewable_percentage": 14.7001731284}, {"Entity": "Thailand", "Year": 2020, "rank": 15, "renewable_percentage": 13.7963737796}, {"Entity": "Ukraine", "Year": 2000, "rank": 13, "renewable_percentage": 6.5860921352}, {"Entity": "Ukraine", "Year": 2001, "rank": 13, "renewable_percentage": 6.9729761009}, {"Entity": "Ukraine", "Year": 2002, "rank": 14, "renewable_percentage": 5.5597165409}, {"Entity": "Ukraine", "Year": 2003, "rank": 14, "renewable_percentage": 5.1442841287}, {"Entity": "Ukraine", "Year": 2004, "rank": 14, "renewable_percentage": 6.4718162839}, {"Entity": "Ukraine", "Year": 2005, "rank": 13, "renewable_percentage": 6.6698940347}, {"Entity": "Ukraine", "Year": 2006, "rank": 14, "renewable_percentage": 6.68633235}, {"Entity": "Ukraine", "Year": 2007, "rank": 14, "renewable_percentage": 5.3380238605}, {"Entity": "Ukraine", "Year": 2008, "rank": 14, "renewable_percentage": 6.1377090041}, {"Entity": "Ukraine", "Year": 2009, "rank": 13, "renewable_percentage": 6.980762585}, {"Entity": "Ukraine", "Year": 2010, "rank": 13, "renewable_percentage": 7.0914098083}, {"Entity": "Ukraine", "Year": 2011, "rank": 16, "renewable_percentage": 5.7450628366}, {"Entity": "Ukraine", "Year": 2012, "rank": 16, "renewable_percentage": 5.6614236741}, {"Entity": "Ukraine", "Year": 2013, "rank": 15, "renewable_percentage": 7.8003200661}, {"Entity": "Ukraine", "Year": 2014, "rank": 16, "renewable_percentage": 5.5885262117}, {"Entity": "Ukraine", "Year": 2015, "rank": 16, "renewable_percentage": 4.3924771096}, {"Entity": "Ukraine", "Year": 2016, "rank": 16, "renewable_percentage": 5.6797249171}, {"Entity": "Ukraine", "Year": 2017, "rank": 16, "renewable_percentage": 7.0457194664}, {"Entity": "Ukraine", "Year": 2018, "rank": 16, "renewable_percentage": 8.228528092}, {"Entity": "Ukraine", "Year": 2019, "rank": 16, "renewable_percentage": 7.7754487096}, {"Entity": "Ukraine", "Year": 2020, "rank": 16, "renewable_percentage": 11.8440577364}, {"Entity": "United Kingdom", "Year": 2000, "rank": 15, "renewable_percentage": 2.6657406913}, {"Entity": "United Kingdom", "Year": 2001, "rank": 15, "renewable_percentage": 2.5001961451}, {"Entity": "United Kingdom", "Year": 2002, "rank": 15, "renewable_percentage": 2.8939157566}, {"Entity": "United Kingdom", "Year": 2003, "rank": 15, "renewable_percentage": 2.6854802003}, {"Entity": "United Kingdom", "Year": 2004, "rank": 15, "renewable_percentage": 3.6136880575}, {"Entity": "United Kingdom", "Year": 2005, "rank": 15, "renewable_percentage": 4.2815234434}, {"Entity": "United Kingdom", "Year": 2006, "rank": 15, "renewable_percentage": 4.6029890199}, {"Entity": "United Kingdom", "Year": 2007, "rank": 15, "renewable_percentage": 5.0104331009}, {"Entity": "United Kingdom", "Year": 2008, "rank": 15, "renewable_percentage": 5.6776842324}, {"Entity": "United Kingdom", "Year": 2009, "rank": 14, "renewable_percentage": 6.7679854187}, {"Entity": "United Kingdom", "Year": 2010, "rank": 15, "renewable_percentage": 6.9092924441}, {"Entity": "United Kingdom", "Year": 2011, "rank": 13, "renewable_percentage": 9.6422505889}, {"Entity": "United Kingdom", "Year": 2012, "rank": 11, "renewable_percentage": 11.4273047189}, {"Entity": "United Kingdom", "Year": 2013, "rank": 10, "renewable_percentage": 14.9727052732}, {"Entity": "United Kingdom", "Year": 2014, "rank": 8, "renewable_percentage": 19.2476358104}, {"Entity": "United Kingdom", "Year": 2015, "rank": 6, "renewable_percentage": 24.6227709191}, {"Entity": "United Kingdom", "Year": 2016, "rank": 7, "renewable_percentage": 24.6788390627}, {"Entity": "United Kingdom", "Year": 2017, "rank": 6, "renewable_percentage": 29.4986571173}, {"Entity": "United Kingdom", "Year": 2018, "rank": 6, "renewable_percentage": 33.2919818457}, {"Entity": "United Kingdom", "Year": 2019, "rank": 5, "renewable_percentage": 37.4568630499}, {"Entity": "United Kingdom", "Year": 2020, "rank": 5, "renewable_percentage": 42.8603962651}, {"Entity": "United States", "Year": 2000, "rank": 10, "renewable_percentage": 9.2298992662}, {"Entity": "United States", "Year": 2001, "rank": 11, "renewable_percentage": 7.5132056541}, {"Entity": "United States", "Year": 2002, "rank": 10, "renewable_percentage": 8.749216358}, {"Entity": "United States", "Year": 2003, "rank": 10, "renewable_percentage": 9.0252110397}, {"Entity": "United States", "Year": 2004, "rank": 11, "renewable_percentage": 8.7334100887}, {"Entity": "United States", "Year": 2005, "rank": 12, "renewable_percentage": 8.7494640631}, {"Entity": "United States", "Year": 2006, "rank": 12, "renewable_percentage": 9.4184742052}, {"Entity": "United States", "Year": 2007, "rank": 12, "renewable_percentage": 8.3984096829}, {"Entity": "United States", "Year": 2008, "rank": 11, "renewable_percentage": 9.180943292}, {"Entity": "United States", "Year": 2009, "rank": 10, "renewable_percentage": 10.547689996}, {"Entity": "United States", "Year": 2010, "rank": 11, "renewable_percentage": 10.3180892283}, {"Entity": "United States", "Year": 2011, "rank": 9, "renewable_percentage": 12.4665249812}, {"Entity": "United States", "Year": 2012, "rank": 10, "renewable_percentage": 12.1841179804}, {"Entity": "United States", "Year": 2013, "rank": 12, "renewable_percentage": 12.8311154179}, {"Entity": "United States", "Year": 2014, "rank": 12, "renewable_percentage": 13.3503092033}, {"Entity": "United States", "Year": 2015, "rank": 14, "renewable_percentage": 13.6261352256}, {"Entity": "United States", "Year": 2016, "rank": 12, "renewable_percentage": 15.2880936304}, {"Entity": "United States", "Year": 2017, "rank": 9, "renewable_percentage": 17.4515276472}, {"Entity": "United States", "Year": 2018, "rank": 11, "renewable_percentage": 17.4499886946}, {"Entity": "United States", "Year": 2019, "rank": 13, "renewable_percentage": 18.2946243489}, {"Entity": "United States", "Year": 2020, "rank": 12, "renewable_percentage": 20.3156921037}], "metadata": {"Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}, "rank": {"type": "number", "semanticType": "Number"}, "renewable_percentage": {"type": "number", "semanticType": "Percentage"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Rank countries by renewable percentage within each year (highest percentage = rank 1)\n df_energy['rank'] = df_energy.groupby('Year')['renewable_percentage'].rank(\n method='dense', \n ascending=False\n )\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage', 'rank']].copy()\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 158029.9988, 190729.9957, 209229.9957, ..., 6993180.176, 9861099.609, 9874660.156, 10096009.77\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 90.14, 91.79, 92.54, 804.95\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Transform the data into a long format where different energy sources (fossil fuels, nuclear, renewables) are unpivoted into separate rows. Each row should contain the year, entity (country), energy source type, and the corresponding energy value in TWh. This will enable visualization of energy generation trends over time by source and country.\",\n \"display_instruction\": \"Show **energy generation** trends by **source** and **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"source\", \"energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n },\n \"reason\": \"The user wants to visualize energy data across different sources with a line chart faceted by source. The original data has energy sources in separate columns (fossil fuels, nuclear, renewables), so we need to unpivot these columns into a long format with 'source' and 'energy' fields. The chart_encodings provided by the user are appropriate for this visualization goal, using faceting (column) to separate different energy sources.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Year energy source\n0 Australia 2000 181.05 fossil fuels\n1 Australia 2001 194.33 fossil fuels\n2 Australia 2002 197.29 fossil fuels\n3 Australia 2003 195.13 fossil fuels\n4 Australia 2004 203.66 fossil fuels\n5 Australia 2005 195.95 fossil fuels\n6 Australia 2006 198.72 fossil fuels\n7 Australia 2007 208.59 fossil fuels\n8 Australia 2008 211.06 fossil fuels\n9 Australia 2009 216.42 fossil fuels\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show renewable percentage for each country\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage for each country and year. The renewable percentage is computed as the ratio of renewable energy to total energy (sum of fossil fuels, nuclear, and renewables) multiplied by 100. The output should contain year, entity (country), and the renewable percentage value.\",\n \"display_instruction\": \"Show **renewable percentage** for each **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"renewable_percentage\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"renewable_percentage\",\n \"color\": \"Entity\"\n },\n \"reason\": \"The user wants to see renewable percentage trends, which requires calculating the proportion of renewable energy relative to total energy generation. This is a single metric per country per year, so we don't need the 'column' faceting by source anymore. The chart_encodings are updated to reflect that we're now showing a percentage metric rather than absolute energy values by source.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage']].copy()\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Year renewable_percentage\n0 Australia 2000 8.634437\n1 Australia 2001 8.218014\n2 Australia 2002 8.083302\n3 Australia 2003 8.659832\n4 Australia 2004 8.701305\n5 Australia 2005 9.156236\n6 Australia 2006 9.635760\n7 Australia 2007 9.119031\n8 Australia 2008 8.054890\n9 Australia 2009 7.804379\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"rank countries by their renewable percentage\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"renewable_percentage\",\n \"color\": \"Entity\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage for each country and year, then rank countries based on their renewable percentage. The ranking should be computed for each year, showing which countries have the highest to lowest renewable percentage. The output should contain year, entity (country), renewable percentage, and the rank of each country within that year.\",\n \"display_instruction\": \"Show **countries ranked** by **renewable percentage** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"renewable_percentage\", \"rank\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"renewable_percentage\",\n \"color\": \"Entity\"\n },\n \"reason\": \"The user wants to rank countries by their renewable percentage, which requires adding a rank field that orders countries within each year based on their renewable percentage (highest percentage = rank 1). This allows comparison of countries' relative positions in renewable energy adoption over time. The chart_encodings remain the same as the previous step since we're still visualizing renewable percentage trends, but now with ranking information available.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Rank countries by renewable percentage within each year (highest percentage = rank 1)\n df_energy['rank'] = df_energy.groupby('Year')['renewable_percentage'].rank(\n method='dense', \n ascending=False\n )\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage', 'rank']].copy()\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-45", "resultTableId": "table-78", "chart": {"id": "chart-1760738441793", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-renewable_percentage-1760738424337"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-45", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "rank countries by their renewable percentage", "displayContent": "Show **countries ranked** by **renewable percentage** over **Year**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "- Calculate **total_energy** for each country-year by summing electricity generated from **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n- Compute **renewable_percentage** by dividing **Electricity from renewables (TWh)** by **total_energy** and multiplying by **100**\n- Replace any infinite values in **renewable_percentage** with NaN to handle cases where total energy is zero\n- Assign a **rank** to each country within each **Year** based on **renewable_percentage**, where rank **1** represents the highest renewable percentage (using dense ranking method)\n- Return a dataset containing **Year**, **Entity** (country name), **renewable_percentage**, and **rank**", "concepts": [{"explanation": "The proportion of a country's total electricity generation that comes from renewable sources, expressed as a percentage. Calculated as: \\[ \\text{renewable\\_percentage} = \\frac{\\text{Electricity from renewables (TWh)}}{\\text{total\\_energy}} \\times 100 \\]", "field": "renewable_percentage"}], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 190729.9957, 227580.0018, 233600.0061, ..., 9282549.805, 9861099.609, 9874660.156, 10096009.77\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 88.76, 90.14, 91.79, 92.54\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Rank countries by renewable percentage within each year (highest percentage = rank 1)\n df_energy['rank'] = df_energy.groupby('Year')['renewable_percentage'].rank(\n method='dense', \n ascending=False\n )\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage', 'rank']].copy()\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\n- Calculate **total_energy** for each country-year by summing electricity generated from **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n- Compute **renewable_percentage** by dividing **Electricity from renewables (TWh)** by **total_energy** and multiplying by **100**\n- Replace any infinite values in **renewable_percentage** with NaN to handle cases where total energy is zero\n- Assign a **rank** to each country within each **Year** based on **renewable_percentage**, where rank **1** represents the highest renewable percentage (using dense ranking method)\n- Return a dataset containing **Year**, **Entity** (country name), **renewable_percentage**, and **rank**\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"renewable_percentage\",\n \"explanation\": \"The proportion of a country's total electricity generation that comes from renewable sources, expressed as a percentage. Calculated as: \\\\[ \\\\text{renewable\\\\_percentage} = \\\\frac{\\\\text{Electricity from renewables (TWh)}}{\\\\text{total\\\\_energy}} \\\\times 100 \\\\]\"\n }\n]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-97", "displayId": "renewable-elec", "names": ["Electricity from renewables (TWh)", "Entity", "Year"], "rows": [{"Electricity from renewables (TWh)": 17.11, "Entity": "Australia", "Year": "2000"}, {"Electricity from renewables (TWh)": 63.99, "Entity": "Australia", "Year": "2020"}, {"Electricity from renewables (TWh)": 308.77, "Entity": "Brazil", "Year": "2000"}, {"Electricity from renewables (TWh)": 520.01, "Entity": "Brazil", "Year": "2020"}, {"Electricity from renewables (TWh)": 363.7, "Entity": "Canada", "Year": "2000"}, {"Electricity from renewables (TWh)": 429.24, "Entity": "Canada", "Year": "2020"}, {"Electricity from renewables (TWh)": 225.56, "Entity": "China", "Year": "2000"}, {"Electricity from renewables (TWh)": 2184.94, "Entity": "China", "Year": "2020"}, {"Electricity from renewables (TWh)": 67.83, "Entity": "France", "Year": "2000"}, {"Electricity from renewables (TWh)": 125.28, "Entity": "France", "Year": "2020"}, {"Electricity from renewables (TWh)": 35.47, "Entity": "Germany", "Year": "2000"}, {"Electricity from renewables (TWh)": 251.48, "Entity": "Germany", "Year": "2020"}, {"Electricity from renewables (TWh)": 80.27, "Entity": "India", "Year": "2000"}, {"Electricity from renewables (TWh)": 315.76, "Entity": "India", "Year": "2020"}, {"Electricity from renewables (TWh)": 19.6, "Entity": "Indonesia", "Year": "2000"}, {"Electricity from renewables (TWh)": 52.91, "Entity": "Indonesia", "Year": "2020"}, {"Electricity from renewables (TWh)": 50.87, "Entity": "Italy", "Year": "2000"}, {"Electricity from renewables (TWh)": 116.9, "Entity": "Italy", "Year": "2020"}, {"Electricity from renewables (TWh)": 104.16, "Entity": "Japan", "Year": "2000"}, {"Electricity from renewables (TWh)": 205.6, "Entity": "Japan", "Year": "2020"}, {"Electricity from renewables (TWh)": 7.53, "Entity": "Kazakhstan", "Year": "2000"}, {"Electricity from renewables (TWh)": 11.94, "Entity": "Kazakhstan", "Year": "2020"}, {"Electricity from renewables (TWh)": 44.51, "Entity": "Mexico", "Year": "2000"}, {"Electricity from renewables (TWh)": 69.19, "Entity": "Mexico", "Year": "2020"}, {"Electricity from renewables (TWh)": 2.33, "Entity": "Poland", "Year": "2000"}, {"Electricity from renewables (TWh)": 28.23, "Entity": "Poland", "Year": "2020"}, {"Electricity from renewables (TWh)": 0, "Entity": "Saudi Arabia", "Year": "2000"}, {"Electricity from renewables (TWh)": 0.21, "Entity": "Saudi Arabia", "Year": "2020"}, {"Electricity from renewables (TWh)": 1.79, "Entity": "South Africa", "Year": "2000"}, {"Electricity from renewables (TWh)": 12.83, "Entity": "South Africa", "Year": "2020"}, {"Electricity from renewables (TWh)": 34.49, "Entity": "Spain", "Year": "2000"}, {"Electricity from renewables (TWh)": 113.79, "Entity": "Spain", "Year": "2020"}, {"Electricity from renewables (TWh)": 6.38, "Entity": "Thailand", "Year": "2000"}, {"Electricity from renewables (TWh)": 24.73, "Entity": "Thailand", "Year": "2020"}, {"Electricity from renewables (TWh)": 11.28, "Entity": "Ukraine", "Year": "2000"}, {"Electricity from renewables (TWh)": 17.56, "Entity": "Ukraine", "Year": "2020"}, {"Electricity from renewables (TWh)": 9.98, "Entity": "United Kingdom", "Year": "2000"}, {"Electricity from renewables (TWh)": 131.74, "Entity": "United Kingdom", "Year": "2020"}, {"Electricity from renewables (TWh)": 350.93, "Entity": "United States", "Year": "2000"}, {"Electricity from renewables (TWh)": 821.4, "Entity": "United States", "Year": "2020"}], "metadata": {"Electricity from renewables (TWh)": {"type": "number", "semanticType": "Number"}, "Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 61.99, 62.21, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"compare each countries renewable between 2000 and 2020\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Energy\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Compare renewable energy (Electricity from renewables) for each country between the years 2000 and 2020. Filter the data to include only years 2000 and 2020, and prepare the output with country names, year, and renewable energy values for visualization as a grouped bar chart.\",\n \"display_instruction\": \"Compare **renewable energy** by **country** between **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Electricity from renewables (TWh)\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to compare renewable energy across countries between 2000 and 2020. The output field 'Renewable Energy' mentioned in the original chart_encodings maps to 'Electricity from renewables (TWh)' in the dataset. To create a grouped bar chart comparing these two years, we need to filter the data to only include years 2000 and 2020, and output the Entity (country), Year, and the renewable energy values. The chart_encodings are updated to use the actual column name from the dataset.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "global-energy-20-small.csv", "resultTableId": "table-97", "chart": {"id": "chart-1760738769634", "chartType": "Grouped Bar Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "y": {"fieldID": "concept-1760738743125"}, "color": {"channel": "color", "bin": false, "fieldID": "original--global-energy-20-small.csv--Year"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}}, "tableRef": "global-energy-20-small.csv", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "compare each countries renewable between 2000 and 2020", "displayContent": "Compare **renewable energy** by **country** between **2000** and **2020**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code performs a straightforward comparison analysis of renewable energy generation across countries:\n\n- **Filters** the dataset to include only data from years **2000** and **2020**, creating a 20-year comparison window\n- **Selects** three key columns: `Entity` (country name), `Year`, and `Electricity from renewables (TWh)` (renewable energy generation)\n- **Converts** the `Year` field to string format to treat it as a categorical variable for visualization purposes\n- **Sorts** the results by `Entity` and `Year` to organize countries alphabetically with their respective year data grouped together\n- **Returns** a cleaned dataset showing how renewable electricity generation has changed for each country between 2000 and 2020", "concepts": [], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 10006669.92, 10502929.69, 10707219.73, nan\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 56.18, 61.99, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code performs a straightforward comparison analysis of renewable energy generation across countries:\n\n- **Filters** the dataset to include only data from years **2000** and **2020**, creating a 20-year comparison window\n- **Selects** three key columns: `Entity` (country name), `Year`, and `Electricity from renewables (TWh)` (renewable energy generation)\n- **Converts** the `Year` field to string format to treat it as a categorical variable for visualization purposes\n- **Sorts** the results by `Entity` and `Year` to organize countries alphabetically with their respective year data grouped together\n- **Returns** a cleaned dataset showing how renewable electricity generation has changed for each country between 2000 and 2020\n\n[CONCEPTS EXPLANATION]\n\n```json\n[]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-27", "displayId": "renewable-energy1", "names": ["Entity", "Renewable Percentage", "Year"], "rows": [{"Entity": "Australia", "Renewable Percentage": 8.6344368187, "Year": "2000"}, {"Entity": "Australia", "Renewable Percentage": 25.5031684668, "Year": "2020"}, {"Entity": "Brazil", "Renewable Percentage": 90.1307723743, "Year": "2000"}, {"Entity": "Brazil", "Renewable Percentage": 84.6411771408, "Year": "2020"}, {"Entity": "Canada", "Renewable Percentage": 61.8095917882, "Year": "2000"}, {"Entity": "Canada", "Renewable Percentage": 68.7796436354, "Year": "2020"}, {"Entity": "China", "Renewable Percentage": 16.639126586, "Year": "2000"}, {"Entity": "China", "Renewable Percentage": 28.2464606924, "Year": "2020"}, {"Entity": "France", "Renewable Percentage": 12.7117691154, "Year": "2000"}, {"Entity": "France", "Renewable Percentage": 23.7610241821, "Year": "2020"}, {"Entity": "Germany", "Renewable Percentage": 6.1977983575, "Year": "2000"}, {"Entity": "Germany", "Renewable Percentage": 44.3324048937, "Year": "2020"}, {"Entity": "Global Average", "Renewable Percentage": 16.4213212559, "Year": "2000"}, {"Entity": "Global Average", "Renewable Percentage": 29.2955247263, "Year": "2020"}, {"Entity": "India", "Renewable Percentage": 14.0481982534, "Year": "2000"}, {"Entity": "India", "Renewable Percentage": 20.2059243238, "Year": "2020"}, {"Entity": "Indonesia", "Renewable Percentage": null, "Year": "2000"}, {"Entity": "Indonesia", "Renewable Percentage": null, "Year": "2020"}, {"Entity": "Italy", "Renewable Percentage": 18.900241501, "Year": "2000"}, {"Entity": "Italy", "Renewable Percentage": 42.0397741576, "Year": "2020"}, {"Entity": "Japan", "Renewable Percentage": 10.5382436261, "Year": "2000"}, {"Entity": "Japan", "Renewable Percentage": 21.324925062, "Year": "2020"}, {"Entity": "Kazakhstan", "Renewable Percentage": null, "Year": "2000"}, {"Entity": "Kazakhstan", "Renewable Percentage": null, "Year": "2020"}, {"Entity": "Mexico", "Renewable Percentage": 22.9291160107, "Year": "2000"}, {"Entity": "Mexico", "Renewable Percentage": 21.2552224134, "Year": "2020"}, {"Entity": "Poland", "Renewable Percentage": 1.6273222517, "Year": "2000"}, {"Entity": "Poland", "Renewable Percentage": 17.9648720886, "Year": "2020"}, {"Entity": "Saudi Arabia", "Renewable Percentage": null, "Year": "2000"}, {"Entity": "Saudi Arabia", "Renewable Percentage": null, "Year": "2020"}, {"Entity": "South Africa", "Renewable Percentage": 0.9110805721, "Year": "2000"}, {"Entity": "South Africa", "Renewable Percentage": 5.780581212, "Year": "2020"}, {"Entity": "Spain", "Renewable Percentage": 15.6119862394, "Year": "2000"}, {"Entity": "Spain", "Renewable Percentage": 43.8108805298, "Year": "2020"}, {"Entity": "Thailand", "Renewable Percentage": 7.1261029822, "Year": "2000"}, {"Entity": "Thailand", "Renewable Percentage": 13.7963737796, "Year": "2020"}, {"Entity": "Ukraine", "Renewable Percentage": 6.5860921352, "Year": "2000"}, {"Entity": "Ukraine", "Renewable Percentage": 11.8440577364, "Year": "2020"}, {"Entity": "United Kingdom", "Renewable Percentage": 2.6657406913, "Year": "2000"}, {"Entity": "United Kingdom", "Renewable Percentage": 42.8603962651, "Year": "2020"}, {"Entity": "United States", "Renewable Percentage": 9.2298992662, "Year": "2000"}, {"Entity": "United States", "Renewable Percentage": 20.3156921037, "Year": "2020"}], "metadata": {"Entity": {"type": "string", "semanticType": "Name"}, "Renewable Percentage": {"type": "number", "semanticType": "Percentage"}, "Year": {"type": "number", "semanticType": "Year"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 61.99, 62.21, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"compare each countries renewable between 2000 and 2020\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Energy\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Compare renewable energy (Electricity from renewables) for each country between the years 2000 and 2020. Filter the data to include only years 2000 and 2020, and prepare the output with country names, year, and renewable energy values for visualization as a grouped bar chart.\",\n \"display_instruction\": \"Compare **renewable energy** by **country** between **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Electricity from renewables (TWh)\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to compare renewable energy across countries between 2000 and 2020. The output field 'Renewable Energy' mentioned in the original chart_encodings maps to 'Electricity from renewables (TWh)' in the dataset. To create a grouped bar chart comparing these two years, we need to filter the data to only include years 2000 and 2020, and output the Entity (country), Year, and the renewable energy values. The chart_encodings are updated to use the actual column name from the dataset.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Electricity from renewables (TWh) Entity Year\n0 17.11 Australia 2000\n1 63.99 Australia 2020\n2 308.77 Brazil 2000\n3 520.01 Brazil 2020\n4 363.70 Canada 2000\n5 429.24 Canada 2020\n6 225.56 China 2000\n7 2184.94 China 2020\n8 67.83 France 2000\n9 125.28 France 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show their renewable percentage instead, and add an entity to show global average\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage (proportion of renewables to total electricity generation from all sources) for each country between 2000 and 2020. Add a 'Global Average' entity that represents the worldwide average renewable percentage for each year. The output should include Entity (with 'Global Average' added), Year, and the renewable percentage.\",\n \"display_instruction\": \"Show **renewable energy percentage** by **country** with **global average** for **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Renewable Percentage\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Percentage\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to see renewable percentage instead of absolute values, and wants to add a global average entity for comparison. Renewable percentage is calculated as the ratio of renewable energy to total electricity generation (fossil fuels + nuclear + renewables). A 'Global Average' entity needs to be computed by aggregating all countries' data for each year. The y-axis encoding is updated to reflect the new metric 'Renewable Percentage'.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-97", "resultTableId": "table-27", "chart": {"id": "chart-1760738813383", "chartType": "Grouped Bar Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "y": {"fieldID": "original--global-energy-20-small.csv--Electricity from renewables (TWh)"}, "color": {"fieldID": "original--global-energy-20-small.csv--Year"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-97", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "show their renewable percentage instead, and add an entity to show global average", "displayContent": "Show **renewable energy percentage** by **country** with **global average** for **2000** and **2020**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code performs the following transformation steps:\n\n1. **Filter data** to include only records from **2000** and **2020**\n2. Calculate **Total Electricity** generation by summing three sources: **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n3. Compute **Renewable Percentage** for each country and year by dividing **Electricity from renewables** by **Total Electricity** and multiplying by 100\n4. Extract relevant columns: **Entity** (country name), **Year**, and **Renewable Percentage**\n5. Calculate **Global Average** renewable percentage for each year by:\n - Summing all countries' **renewable electricity** generation\n - Dividing by the sum of all countries' **total electricity** generation\n - Multiplying by 100 to get percentage\n6. Combine individual country data with the **Global Average** statistics\n7. Convert **Year** values to string format\n8. Sort results by **Entity** name and **Year**", "concepts": [{"explanation": "The sum of electricity generated from all three sources (fossil fuels, nuclear, and renewables) measured in terawatt-hours (TWh). This represents the total electricity production capacity for each country.", "field": "Total Electricity"}, {"explanation": "The proportion of electricity generated from renewable sources relative to total electricity production, expressed as a percentage: \\( \\text{Renewable Percentage} = \\frac{\\text{Electricity from renewables}}{\\text{Total Electricity}} \\times 100 \\). This metric indicates the extent of renewable energy adoption in a country's electricity mix.", "field": "Renewable Percentage"}], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 10096009.77, 10502929.69, 10707219.73, nan\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., nan, nan, nan, nan\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code performs the following transformation steps:\n\n1. **Filter data** to include only records from **2000** and **2020**\n2. Calculate **Total Electricity** generation by summing three sources: **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n3. Compute **Renewable Percentage** for each country and year by dividing **Electricity from renewables** by **Total Electricity** and multiplying by 100\n4. Extract relevant columns: **Entity** (country name), **Year**, and **Renewable Percentage**\n5. Calculate **Global Average** renewable percentage for each year by:\n - Summing all countries' **renewable electricity** generation\n - Dividing by the sum of all countries' **total electricity** generation\n - Multiplying by 100 to get percentage\n6. Combine individual country data with the **Global Average** statistics\n7. Convert **Year** values to string format\n8. Sort results by **Entity** name and **Year**\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"Total Electricity\",\n \"explanation\": \"The sum of electricity generated from all three sources (fossil fuels, nuclear, and renewables) measured in terawatt-hours (TWh). This represents the total electricity production capacity for each country.\"\n },\n {\n \"field\": \"Renewable Percentage\",\n \"explanation\": \"The proportion of electricity generated from renewable sources relative to total electricity production, expressed as a percentage: \\\\( \\\\text{Renewable Percentage} = \\\\frac{\\\\text{Electricity from renewables}}{\\\\text{Total Electricity}} \\\\times 100 \\\\). This metric indicates the extent of renewable energy adoption in a country's electricity mix.\"\n }\n]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-81", "displayId": "energy-source1", "names": ["Energy", "Energy Source", "Year"], "rows": [{"Energy": 7160.71, "Energy Source": "Fossil Fuels", "Year": 2000}, {"Energy": 1996.65, "Energy Source": "Nuclear", "Year": 2000}, {"Energy": 1742.56, "Energy Source": "Renewables", "Year": 2000}, {"Energy": 7273.89, "Energy Source": "Fossil Fuels", "Year": 2001}, {"Energy": 2037.54, "Energy Source": "Nuclear", "Year": 2001}, {"Energy": 1690.11, "Energy Source": "Renewables", "Year": 2001}, {"Energy": 7621.07, "Energy Source": "Fossil Fuels", "Year": 2002}, {"Energy": 2042.18, "Energy Source": "Nuclear", "Year": 2002}, {"Energy": 1757.63, "Energy Source": "Renewables", "Year": 2002}, {"Energy": 8043.86, "Energy Source": "Fossil Fuels", "Year": 2003}, {"Energy": 1998.52, "Energy Source": "Nuclear", "Year": 2003}, {"Energy": 1804.52, "Energy Source": "Renewables", "Year": 2003}, {"Energy": 8399.72, "Energy Source": "Fossil Fuels", "Year": 2004}, {"Energy": 2095, "Energy Source": "Nuclear", "Year": 2004}, {"Energy": 1952.72, "Energy Source": "Renewables", "Year": 2004}, {"Energy": 8828.43, "Energy Source": "Fossil Fuels", "Year": 2005}, {"Energy": 2094.4, "Energy Source": "Nuclear", "Year": 2005}, {"Energy": 2025.26, "Energy Source": "Renewables", "Year": 2005}, {"Energy": 9183.05, "Energy Source": "Fossil Fuels", "Year": 2006}, {"Energy": 2120.38, "Energy Source": "Nuclear", "Year": 2006}, {"Energy": 2165.94, "Energy Source": "Renewables", "Year": 2006}, {"Energy": 9853.09, "Energy Source": "Fossil Fuels", "Year": 2007}, {"Energy": 2067.04, "Energy Source": "Nuclear", "Year": 2007}, {"Energy": 2256.79, "Energy Source": "Renewables", "Year": 2007}, {"Energy": 9817.15, "Energy Source": "Fossil Fuels", "Year": 2008}, {"Energy": 2043.94, "Energy Source": "Nuclear", "Year": 2008}, {"Energy": 2496.03, "Energy Source": "Renewables", "Year": 2008}, {"Energy": 9686.86, "Energy Source": "Fossil Fuels", "Year": 2009}, {"Energy": 2017.25, "Energy Source": "Nuclear", "Year": 2009}, {"Energy": 2563.95, "Energy Source": "Renewables", "Year": 2009}, {"Energy": 10427.03, "Energy Source": "Fossil Fuels", "Year": 2010}, {"Energy": 2083.37, "Energy Source": "Nuclear", "Year": 2010}, {"Energy": 2802.89, "Energy Source": "Renewables", "Year": 2010}, {"Energy": 10974.83, "Energy Source": "Fossil Fuels", "Year": 2011}, {"Energy": 1956, "Energy Source": "Nuclear", "Year": 2011}, {"Energy": 2997.29, "Energy Source": "Renewables", "Year": 2011}, {"Energy": 11277.49, "Energy Source": "Fossil Fuels", "Year": 2012}, {"Energy": 1788.26, "Energy Source": "Nuclear", "Year": 2012}, {"Energy": 3226.1, "Energy Source": "Renewables", "Year": 2012}, {"Energy": 11561.86, "Energy Source": "Fossil Fuels", "Year": 2013}, {"Energy": 1813, "Energy Source": "Nuclear", "Year": 2013}, {"Energy": 3473.9, "Energy Source": "Renewables", "Year": 2013}, {"Energy": 11761.51, "Energy Source": "Fossil Fuels", "Year": 2014}, {"Energy": 1847.87, "Energy Source": "Nuclear", "Year": 2014}, {"Energy": 3753.03, "Energy Source": "Renewables", "Year": 2014}, {"Energy": 11653.61, "Energy Source": "Fossil Fuels", "Year": 2015}, {"Energy": 1886.61, "Energy Source": "Nuclear", "Year": 2015}, {"Energy": 3903.7, "Energy Source": "Renewables", "Year": 2015}, {"Energy": 11785.35, "Energy Source": "Fossil Fuels", "Year": 2016}, {"Energy": 1906.92, "Energy Source": "Nuclear", "Year": 2016}, {"Energy": 4186.83, "Energy Source": "Renewables", "Year": 2016}, {"Energy": 12003.24, "Energy Source": "Fossil Fuels", "Year": 2017}, {"Energy": 1942.94, "Energy Source": "Nuclear", "Year": 2017}, {"Energy": 4500.22, "Energy Source": "Renewables", "Year": 2017}, {"Energy": 12445.24, "Energy Source": "Fossil Fuels", "Year": 2018}, {"Energy": 2016.82, "Energy Source": "Nuclear", "Year": 2018}, {"Energy": 4834.65, "Energy Source": "Renewables", "Year": 2018}, {"Energy": 12355.91, "Energy Source": "Fossil Fuels", "Year": 2019}, {"Energy": 2073.87, "Energy Source": "Nuclear", "Year": 2019}, {"Energy": 5146.11, "Energy Source": "Renewables", "Year": 2019}, {"Energy": 12032.75, "Energy Source": "Fossil Fuels", "Year": 2020}, {"Energy": 1974.46, "Energy Source": "Nuclear", "Year": 2020}, {"Energy": 5497.73, "Energy Source": "Renewables", "Year": 2020}], "metadata": {"Energy": {"type": "number", "semanticType": "Number"}, "Energy Source": {"type": "string", "semanticType": "String", "levels": ["Fossil Fuels", "Nuclear", "Renewables"]}, "Year": {"type": "number", "semanticType": "Year"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Group by Year and sum electricity generation from all countries\n global_energy = df_energy.groupby('Year').agg({\n 'Electricity from fossil fuels (TWh)': 'sum',\n 'Electricity from nuclear (TWh)': 'sum',\n 'Electricity from renewables (TWh)': 'sum'\n }).reset_index()\n \n # Rename columns for clarity\n global_energy.columns = ['Year', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n global_energy,\n id_vars=['Year'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Year and Energy Source\n transformed_df = transformed_df.sort_values(['Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 61.99, 62.21, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"compare each countries renewable between 2000 and 2020\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Energy\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Compare renewable energy (Electricity from renewables) for each country between the years 2000 and 2020. Filter the data to include only years 2000 and 2020, and prepare the output with country names, year, and renewable energy values for visualization as a grouped bar chart.\",\n \"display_instruction\": \"Compare **renewable energy** by **country** between **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Electricity from renewables (TWh)\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to compare renewable energy across countries between 2000 and 2020. The output field 'Renewable Energy' mentioned in the original chart_encodings maps to 'Electricity from renewables (TWh)' in the dataset. To create a grouped bar chart comparing these two years, we need to filter the data to only include years 2000 and 2020, and output the Entity (country), Year, and the renewable energy values. The chart_encodings are updated to use the actual column name from the dataset.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Electricity from renewables (TWh) Entity Year\n0 17.11 Australia 2000\n1 63.99 Australia 2020\n2 308.77 Brazil 2000\n3 520.01 Brazil 2020\n4 363.70 Canada 2000\n5 429.24 Canada 2020\n6 225.56 China 2000\n7 2184.94 China 2020\n8 67.83 France 2000\n9 125.28 France 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show their renewable percentage instead, and add an entity to show global average\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage (proportion of renewables to total electricity generation from all sources) for each country between 2000 and 2020. Add a 'Global Average' entity that represents the worldwide average renewable percentage for each year. The output should include Entity (with 'Global Average' added), Year, and the renewable percentage.\",\n \"display_instruction\": \"Show **renewable energy percentage** by **country** with **global average** for **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Renewable Percentage\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Percentage\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to see renewable percentage instead of absolute values, and wants to add a global average entity for comparison. Renewable percentage is calculated as the ratio of renewable energy to total electricity generation (fossil fuels + nuclear + renewables). A 'Global Average' entity needs to be computed by aggregating all countries' data for each year. The y-axis encoding is updated to reflect the new metric 'Renewable Percentage'.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Renewable Percentage Year\n0 Australia 8.634437 2000\n1 Australia 25.503168 2020\n2 Brazil 90.130772 2000\n3 Brazil 84.641177 2020\n4 Canada 61.809592 2000\n5 Canada 68.779644 2020\n6 China 16.639127 2000\n7 China 28.246461 2020\n8 France 12.711769 2000\n9 France 23.761024 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show global energy composition over time\",\n \"chart_type\": \"Custom Area\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Show the global energy composition over time by aggregating electricity generation from all countries for each year, broken down by energy source (fossil fuels, nuclear, and renewables). The output should be in long format with Year, Energy Source, and Energy values to support a stacked area chart visualization.\",\n \"display_instruction\": \"Show global **energy composition** by **energy source** over time\",\n \"output_fields\": [\"Year\", \"Energy Source\", \"Energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n },\n \"reason\": \"The user wants to visualize global energy composition over time, which requires aggregating electricity generation data across all countries for each year and breaking it down by energy source type. The data needs to be transformed into long format where each row represents a year-energy source combination, with the total energy value for that source globally. This follows up from the previous renewable percentage analysis by showing the overall energy mix trends rather than focusing on specific countries or percentages.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Group by Year and sum electricity generation from all countries\n global_energy = df_energy.groupby('Year').agg({\n 'Electricity from fossil fuels (TWh)': 'sum',\n 'Electricity from nuclear (TWh)': 'sum',\n 'Electricity from renewables (TWh)': 'sum'\n }).reset_index()\n \n # Rename columns for clarity\n global_energy.columns = ['Year', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n global_energy,\n id_vars=['Year'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Year and Energy Source\n transformed_df = transformed_df.sort_values(['Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-27", "resultTableId": "table-81", "chart": {"id": "chart-1760738942326", "chartType": "Custom Area", "encodingMap": {"x": {"channel": "x", "bin": false, "fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"channel": "y", "bin": false, "fieldID": "concept-1760738917347"}, "x2": {"channel": "x2", "bin": false}, "y2": {"channel": "y2", "bin": false}, "color": {"channel": "color", "bin": false, "fieldID": "concept-1760738921927"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-27", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "show global energy composition over time", "displayContent": "Show global **energy composition** by **energy source** over time"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "- Group the energy data by **Year** and aggregate electricity generation values across all countries by summing **Electricity from fossil fuels (TWh)**, **Electricity from nuclear (TWh)**, and **Electricity from renewables (TWh)**\n- Rename the aggregated columns to simplified labels: **Fossil Fuels**, **Nuclear**, and **Renewables**\n- Transform the data from wide format to long format by unpivoting the three energy source columns into two columns: **Energy Source** (containing the type of energy) and **Energy** (containing the generation value in TWh)\n- Sort the resulting dataset by **Year** and **Energy Source** for consistent ordering", "concepts": [], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 158029.9988, 190729.9957, 209229.9957, ..., nan, 4956060.059, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., nan, nan, nan, nan\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Group by Year and sum electricity generation from all countries\n global_energy = df_energy.groupby('Year').agg({\n 'Electricity from fossil fuels (TWh)': 'sum',\n 'Electricity from nuclear (TWh)': 'sum',\n 'Electricity from renewables (TWh)': 'sum'\n }).reset_index()\n \n # Rename columns for clarity\n global_energy.columns = ['Year', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n global_energy,\n id_vars=['Year'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Year and Energy Source\n transformed_df = transformed_df.sort_values(['Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\n- Group the energy data by **Year** and aggregate electricity generation values across all countries by summing **Electricity from fossil fuels (TWh)**, **Electricity from nuclear (TWh)**, and **Electricity from renewables (TWh)**\n- Rename the aggregated columns to simplified labels: **Fossil Fuels**, **Nuclear**, and **Renewables**\n- Transform the data from wide format to long format by unpivoting the three energy source columns into two columns: **Energy Source** (containing the type of energy) and **Energy** (containing the generation value in TWh)\n- Sort the resulting dataset by **Year** and **Energy Source** for consistent ordering\n\n[CONCEPTS EXPLANATION]\n\n```json\n[]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-10", "displayId": "energy-source2", "names": ["Energy", "Energy Source", "Entity", "Year"], "rows": [{"Energy": 1113.3, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2000}, {"Energy": 16.74, "Energy Source": "Nuclear", "Entity": "China", "Year": 2000}, {"Energy": 225.56, "Energy Source": "Renewables", "Entity": "China", "Year": 2000}, {"Energy": 1182.59, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2001}, {"Energy": 17.47, "Energy Source": "Nuclear", "Entity": "China", "Year": 2001}, {"Energy": 280.73, "Energy Source": "Renewables", "Entity": "China", "Year": 2001}, {"Energy": 1337.46, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2002}, {"Energy": 25.13, "Energy Source": "Nuclear", "Entity": "China", "Year": 2002}, {"Energy": 291.41, "Energy Source": "Renewables", "Entity": "China", "Year": 2002}, {"Energy": 1579.96, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2003}, {"Energy": 43.34, "Energy Source": "Nuclear", "Entity": "China", "Year": 2003}, {"Energy": 287.28, "Energy Source": "Renewables", "Entity": "China", "Year": 2003}, {"Energy": 1795.41, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2004}, {"Energy": 50.47, "Energy Source": "Nuclear", "Entity": "China", "Year": 2004}, {"Energy": 357.43, "Energy Source": "Renewables", "Entity": "China", "Year": 2004}, {"Energy": 2042.8, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2005}, {"Energy": 53.09, "Energy Source": "Nuclear", "Entity": "China", "Year": 2005}, {"Energy": 404.37, "Energy Source": "Renewables", "Entity": "China", "Year": 2005}, {"Energy": 2364.16, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2006}, {"Energy": 54.84, "Energy Source": "Nuclear", "Entity": "China", "Year": 2006}, {"Energy": 446.72, "Energy Source": "Renewables", "Entity": "China", "Year": 2006}, {"Energy": 2718.7, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2007}, {"Energy": 62.13, "Energy Source": "Nuclear", "Entity": "China", "Year": 2007}, {"Energy": 500.71, "Energy Source": "Renewables", "Entity": "China", "Year": 2007}, {"Energy": 2762.29, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2008}, {"Energy": 68.39, "Energy Source": "Nuclear", "Entity": "China", "Year": 2008}, {"Energy": 665.08, "Energy Source": "Renewables", "Entity": "China", "Year": 2008}, {"Energy": 2980.2, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2009}, {"Energy": 70.05, "Energy Source": "Nuclear", "Entity": "China", "Year": 2009}, {"Energy": 664.39, "Energy Source": "Renewables", "Entity": "China", "Year": 2009}, {"Energy": 3326.19, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2010}, {"Energy": 74.74, "Energy Source": "Nuclear", "Entity": "China", "Year": 2010}, {"Energy": 786.38, "Energy Source": "Renewables", "Entity": "China", "Year": 2010}, {"Energy": 3811.77, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2011}, {"Energy": 87.2, "Energy Source": "Nuclear", "Entity": "China", "Year": 2011}, {"Energy": 792.38, "Energy Source": "Renewables", "Entity": "China", "Year": 2011}, {"Energy": 3869.38, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2012}, {"Energy": 98.32, "Energy Source": "Nuclear", "Entity": "China", "Year": 2012}, {"Energy": 999.56, "Energy Source": "Renewables", "Entity": "China", "Year": 2012}, {"Energy": 4203.77, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2013}, {"Energy": 111.5, "Energy Source": "Nuclear", "Entity": "China", "Year": 2013}, {"Energy": 1093.37, "Energy Source": "Renewables", "Entity": "China", "Year": 2013}, {"Energy": 4345.86, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2014}, {"Energy": 133.22, "Energy Source": "Nuclear", "Entity": "China", "Year": 2014}, {"Energy": 1289.23, "Energy Source": "Renewables", "Entity": "China", "Year": 2014}, {"Energy": 4222.76, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2015}, {"Energy": 171.38, "Energy Source": "Nuclear", "Entity": "China", "Year": 2015}, {"Energy": 1393.66, "Energy Source": "Renewables", "Entity": "China", "Year": 2015}, {"Energy": 4355, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2016}, {"Energy": 213.18, "Energy Source": "Nuclear", "Entity": "China", "Year": 2016}, {"Energy": 1522.79, "Energy Source": "Renewables", "Entity": "China", "Year": 2016}, {"Energy": 4643.1, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2017}, {"Energy": 248.1, "Energy Source": "Nuclear", "Entity": "China", "Year": 2017}, {"Energy": 1667.06, "Energy Source": "Renewables", "Entity": "China", "Year": 2017}, {"Energy": 4990.28, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2018}, {"Energy": 295, "Energy Source": "Nuclear", "Entity": "China", "Year": 2018}, {"Energy": 1835.32, "Energy Source": "Renewables", "Entity": "China", "Year": 2018}, {"Energy": 5098.22, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2019}, {"Energy": 348.7, "Energy Source": "Nuclear", "Entity": "China", "Year": 2019}, {"Energy": 2014.57, "Energy Source": "Renewables", "Entity": "China", "Year": 2019}, {"Energy": 5184.13, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2020}, {"Energy": 366.2, "Energy Source": "Nuclear", "Entity": "China", "Year": 2020}, {"Energy": 2184.94, "Energy Source": "Renewables", "Entity": "China", "Year": 2020}, {"Energy": 475.35, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2000}, {"Energy": 15.77, "Energy Source": "Nuclear", "Entity": "India", "Year": 2000}, {"Energy": 80.27, "Energy Source": "Renewables", "Entity": "India", "Year": 2000}, {"Energy": 491.01, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2001}, {"Energy": 18.89, "Energy Source": "Nuclear", "Entity": "India", "Year": 2001}, {"Energy": 76.19, "Energy Source": "Renewables", "Entity": "India", "Year": 2001}, {"Energy": 517.51, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2002}, {"Energy": 19.35, "Energy Source": "Nuclear", "Entity": "India", "Year": 2002}, {"Energy": 72.78, "Energy Source": "Renewables", "Entity": "India", "Year": 2002}, {"Energy": 545.36, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2003}, {"Energy": 18.14, "Energy Source": "Nuclear", "Entity": "India", "Year": 2003}, {"Energy": 74.63, "Energy Source": "Renewables", "Entity": "India", "Year": 2003}, {"Energy": 567.86, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2004}, {"Energy": 21.26, "Energy Source": "Nuclear", "Entity": "India", "Year": 2004}, {"Energy": 109.2, "Energy Source": "Renewables", "Entity": "India", "Year": 2004}, {"Energy": 579.32, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2005}, {"Energy": 17.73, "Energy Source": "Nuclear", "Entity": "India", "Year": 2005}, {"Energy": 107.47, "Energy Source": "Renewables", "Entity": "India", "Year": 2005}, {"Energy": 599.24, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2006}, {"Energy": 17.63, "Energy Source": "Nuclear", "Entity": "India", "Year": 2006}, {"Energy": 127.56, "Energy Source": "Renewables", "Entity": "India", "Year": 2006}, {"Energy": 636.68, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2007}, {"Energy": 17.83, "Energy Source": "Nuclear", "Entity": "India", "Year": 2007}, {"Energy": 141.75, "Energy Source": "Renewables", "Entity": "India", "Year": 2007}, {"Energy": 674.27, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2008}, {"Energy": 15.23, "Energy Source": "Nuclear", "Entity": "India", "Year": 2008}, {"Energy": 138.91, "Energy Source": "Renewables", "Entity": "India", "Year": 2008}, {"Energy": 728.56, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2009}, {"Energy": 16.82, "Energy Source": "Nuclear", "Entity": "India", "Year": 2009}, {"Energy": 134.33, "Energy Source": "Renewables", "Entity": "India", "Year": 2009}, {"Energy": 771.78, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2010}, {"Energy": 23.08, "Energy Source": "Nuclear", "Entity": "India", "Year": 2010}, {"Energy": 142.61, "Energy Source": "Renewables", "Entity": "India", "Year": 2010}, {"Energy": 828.16, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2011}, {"Energy": 32.22, "Energy Source": "Nuclear", "Entity": "India", "Year": 2011}, {"Energy": 173.62, "Energy Source": "Renewables", "Entity": "India", "Year": 2011}, {"Energy": 893.45, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2012}, {"Energy": 33.14, "Energy Source": "Nuclear", "Entity": "India", "Year": 2012}, {"Energy": 165.25, "Energy Source": "Renewables", "Entity": "India", "Year": 2012}, {"Energy": 924.93, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2013}, {"Energy": 33.31, "Energy Source": "Nuclear", "Entity": "India", "Year": 2013}, {"Energy": 187.9, "Energy Source": "Renewables", "Entity": "India", "Year": 2013}, {"Energy": 1025.29, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2014}, {"Energy": 34.69, "Energy Source": "Nuclear", "Entity": "India", "Year": 2014}, {"Energy": 202.04, "Energy Source": "Renewables", "Entity": "India", "Year": 2014}, {"Energy": 1080.44, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2015}, {"Energy": 38.31, "Energy Source": "Nuclear", "Entity": "India", "Year": 2015}, {"Energy": 203.21, "Energy Source": "Renewables", "Entity": "India", "Year": 2015}, {"Energy": 1155.52, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2016}, {"Energy": 37.9, "Energy Source": "Nuclear", "Entity": "India", "Year": 2016}, {"Energy": 208.21, "Energy Source": "Renewables", "Entity": "India", "Year": 2016}, {"Energy": 1198.85, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2017}, {"Energy": 37.41, "Energy Source": "Nuclear", "Entity": "India", "Year": 2017}, {"Energy": 234.9, "Energy Source": "Renewables", "Entity": "India", "Year": 2017}, {"Energy": 1276.32, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2018}, {"Energy": 39.05, "Energy Source": "Nuclear", "Entity": "India", "Year": 2018}, {"Energy": 263.61, "Energy Source": "Renewables", "Entity": "India", "Year": 2018}, {"Energy": 1273.59, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2019}, {"Energy": 45.16, "Energy Source": "Nuclear", "Entity": "India", "Year": 2019}, {"Energy": 303.16, "Energy Source": "Renewables", "Entity": "India", "Year": 2019}, {"Energy": 1202.34, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2020}, {"Energy": 44.61, "Energy Source": "Nuclear", "Entity": "India", "Year": 2020}, {"Energy": 315.76, "Energy Source": "Renewables", "Entity": "India", "Year": 2020}, {"Energy": 2697.28, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2000}, {"Energy": 753.89, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2000}, {"Energy": 350.93, "Energy Source": "Renewables", "Entity": "United States", "Year": 2000}, {"Energy": 2678.68, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2001}, {"Energy": 768.83, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2001}, {"Energy": 280.06, "Energy Source": "Renewables", "Entity": "United States", "Year": 2001}, {"Energy": 2727.83, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2002}, {"Energy": 780.06, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2002}, {"Energy": 336.34, "Energy Source": "Renewables", "Entity": "United States", "Year": 2002}, {"Energy": 2756.03, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2003}, {"Energy": 763.73, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2003}, {"Energy": 349.18, "Energy Source": "Renewables", "Entity": "United States", "Year": 2003}, {"Energy": 2818.28, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2004}, {"Energy": 788.53, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2004}, {"Energy": 345.14, "Energy Source": "Renewables", "Entity": "United States", "Year": 2004}, {"Energy": 2899.96, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2005}, {"Energy": 781.99, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2005}, {"Energy": 353.04, "Energy Source": "Renewables", "Entity": "United States", "Year": 2005}, {"Energy": 2878.56, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2006}, {"Energy": 787.22, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2006}, {"Energy": 381.16, "Energy Source": "Renewables", "Entity": "United States", "Year": 2006}, {"Energy": 2988.24, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2007}, {"Energy": 806.42, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2007}, {"Energy": 347.91, "Energy Source": "Renewables", "Entity": "United States", "Year": 2007}, {"Energy": 2924.21, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2008}, {"Energy": 806.21, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2008}, {"Energy": 377.11, "Energy Source": "Renewables", "Entity": "United States", "Year": 2008}, {"Energy": 2725.41, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2009}, {"Energy": 798.85, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2009}, {"Energy": 415.56, "Energy Source": "Renewables", "Entity": "United States", "Year": 2009}, {"Energy": 2882.49, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2010}, {"Energy": 806.97, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2010}, {"Energy": 424.48, "Energy Source": "Renewables", "Entity": "United States", "Year": 2010}, {"Energy": 2788.93, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2011}, {"Energy": 790.2, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2011}, {"Energy": 509.74, "Energy Source": "Renewables", "Entity": "United States", "Year": 2011}, {"Energy": 2779.02, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2012}, {"Energy": 769.33, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2012}, {"Energy": 492.32, "Energy Source": "Renewables", "Entity": "United States", "Year": 2012}, {"Energy": 2746.21, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2013}, {"Energy": 789.02, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2013}, {"Energy": 520.38, "Energy Source": "Renewables", "Entity": "United States", "Year": 2013}, {"Energy": 2752.01, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2014}, {"Energy": 797.17, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2014}, {"Energy": 546.83, "Energy Source": "Renewables", "Entity": "United States", "Year": 2014}, {"Energy": 2730.32, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2015}, {"Energy": 797.18, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2015}, {"Energy": 556.49, "Energy Source": "Renewables", "Entity": "United States", "Year": 2015}, {"Energy": 2656.96, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2016}, {"Energy": 805.69, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2016}, {"Energy": 624.91, "Energy Source": "Renewables", "Entity": "United States", "Year": 2016}, {"Energy": 2540.17, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2017}, {"Energy": 804.95, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2017}, {"Energy": 707.19, "Energy Source": "Renewables", "Entity": "United States", "Year": 2017}, {"Energy": 2661.3, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2018}, {"Energy": 807.08, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2018}, {"Energy": 733.17, "Energy Source": "Renewables", "Entity": "United States", "Year": 2018}, {"Energy": 2588.21, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2019}, {"Energy": 809.41, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2019}, {"Energy": 760.76, "Energy Source": "Renewables", "Entity": "United States", "Year": 2019}, {"Energy": 2431.9, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2020}, {"Energy": 789.88, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2020}, {"Energy": 821.4, "Energy Source": "Renewables", "Entity": "United States", "Year": 2020}], "metadata": {"Energy": {"type": "number", "semanticType": "Number"}, "Energy Source": {"type": "string", "semanticType": "String", "levels": ["Fossil Fuels", "Nuclear", "Renewables"]}, "Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total CO2 emissions by country across all years\n total_co2_by_country = df_energy.groupby('Entity')['Value_co2_emissions_kt_by_country'].sum().reset_index()\n \n # Get top 3 CO2 emitting countries\n top3_countries = total_co2_by_country.nlargest(3, 'Value_co2_emissions_kt_by_country')['Entity'].tolist()\n \n # Filter data for top 3 countries\n df_top3 = df_energy[df_energy['Entity'].isin(top3_countries)].copy()\n \n # Select relevant columns and rename for clarity\n df_top3 = df_top3[['Year', 'Entity', 'Electricity from fossil fuels (TWh)', \n 'Electricity from nuclear (TWh)', 'Electricity from renewables (TWh)']].copy()\n \n df_top3.columns = ['Year', 'Entity', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n df_top3,\n id_vars=['Year', 'Entity'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Entity, Year, and Energy Source\n transformed_df = transformed_df.sort_values(['Entity', 'Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 61.99, 62.21, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"compare each countries renewable between 2000 and 2020\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Energy\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Compare renewable energy (Electricity from renewables) for each country between the years 2000 and 2020. Filter the data to include only years 2000 and 2020, and prepare the output with country names, year, and renewable energy values for visualization as a grouped bar chart.\",\n \"display_instruction\": \"Compare **renewable energy** by **country** between **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Electricity from renewables (TWh)\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to compare renewable energy across countries between 2000 and 2020. The output field 'Renewable Energy' mentioned in the original chart_encodings maps to 'Electricity from renewables (TWh)' in the dataset. To create a grouped bar chart comparing these two years, we need to filter the data to only include years 2000 and 2020, and output the Entity (country), Year, and the renewable energy values. The chart_encodings are updated to use the actual column name from the dataset.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Electricity from renewables (TWh) Entity Year\n0 17.11 Australia 2000\n1 63.99 Australia 2020\n2 308.77 Brazil 2000\n3 520.01 Brazil 2020\n4 363.70 Canada 2000\n5 429.24 Canada 2020\n6 225.56 China 2000\n7 2184.94 China 2020\n8 67.83 France 2000\n9 125.28 France 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show their renewable percentage instead, and add an entity to show global average\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage (proportion of renewables to total electricity generation from all sources) for each country between 2000 and 2020. Add a 'Global Average' entity that represents the worldwide average renewable percentage for each year. The output should include Entity (with 'Global Average' added), Year, and the renewable percentage.\",\n \"display_instruction\": \"Show **renewable energy percentage** by **country** with **global average** for **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Renewable Percentage\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Percentage\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to see renewable percentage instead of absolute values, and wants to add a global average entity for comparison. Renewable percentage is calculated as the ratio of renewable energy to total electricity generation (fossil fuels + nuclear + renewables). A 'Global Average' entity needs to be computed by aggregating all countries' data for each year. The y-axis encoding is updated to reflect the new metric 'Renewable Percentage'.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Renewable Percentage Year\n0 Australia 8.634437 2000\n1 Australia 25.503168 2020\n2 Brazil 90.130772 2000\n3 Brazil 84.641177 2020\n4 Canada 61.809592 2000\n5 Canada 68.779644 2020\n6 China 16.639127 2000\n7 China 28.246461 2020\n8 France 12.711769 2000\n9 France 23.761024 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show global energy composition over time\",\n \"chart_type\": \"Custom Area\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Show the global energy composition over time by aggregating electricity generation from all countries for each year, broken down by energy source (fossil fuels, nuclear, and renewables). The output should be in long format with Year, Energy Source, and Energy values to support a stacked area chart visualization.\",\n \"display_instruction\": \"Show global **energy composition** by **energy source** over time\",\n \"output_fields\": [\"Year\", \"Energy Source\", \"Energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n },\n \"reason\": \"The user wants to visualize global energy composition over time, which requires aggregating electricity generation data across all countries for each year and breaking it down by energy source type. The data needs to be transformed into long format where each row represents a year-energy source combination, with the total energy value for that source globally. This follows up from the previous renewable percentage analysis by showing the overall energy mix trends rather than focusing on specific countries or percentages.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Group by Year and sum electricity generation from all countries\n global_energy = df_energy.groupby('Year').agg({\n 'Electricity from fossil fuels (TWh)': 'sum',\n 'Electricity from nuclear (TWh)': 'sum',\n 'Electricity from renewables (TWh)': 'sum'\n }).reset_index()\n \n # Rename columns for clarity\n global_energy.columns = ['Year', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n global_energy,\n id_vars=['Year'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Year and Energy Source\n transformed_df = transformed_df.sort_values(['Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Energy Energy Source Year\n0 7160.71 Fossil Fuels 2000\n1 1996.65 Nuclear 2000\n2 1742.56 Renewables 2000\n3 7273.89 Fossil Fuels 2001\n4 2037.54 Nuclear 2001\n5 1690.11 Renewables 2001\n6 7621.07 Fossil Fuels 2002\n7 2042.18 Nuclear 2002\n8 1757.63 Renewables 2002\n9 8043.86 Fossil Fuels 2003\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show the composition of top 3 CO2 emitting countries\",\n \"chart_type\": \"Custom Area\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Identify the top 3 CO2 emitting countries based on total CO2 emissions across all years, then show the energy composition (fossil fuels, nuclear, and renewables) for each of these countries over time. The output should be in long format with Year, Entity (country), Energy Source, and Energy values to support faceted area charts.\",\n \"display_instruction\": \"Show **energy composition** of **top 3 CO2 emitting countries** over time\",\n \"output_fields\": [\"Year\", \"Entity\", \"Energy Source\", \"Energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\",\n \"facet\": \"Entity\"\n },\n \"reason\": \"The user wants to see the energy composition specifically for the top 3 CO2 emitting countries over time, following up from the global energy composition view. We need to identify which countries have the highest total CO2 emissions, filter the data for those countries, and transform it into long format by energy source. A facet encoding is added to show separate area charts for each of the top 3 countries, allowing comparison of their individual energy compositions over time.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total CO2 emissions by country across all years\n total_co2_by_country = df_energy.groupby('Entity')['Value_co2_emissions_kt_by_country'].sum().reset_index()\n \n # Get top 3 CO2 emitting countries\n top3_countries = total_co2_by_country.nlargest(3, 'Value_co2_emissions_kt_by_country')['Entity'].tolist()\n \n # Filter data for top 3 countries\n df_top3 = df_energy[df_energy['Entity'].isin(top3_countries)].copy()\n \n # Select relevant columns and rename for clarity\n df_top3 = df_top3[['Year', 'Entity', 'Electricity from fossil fuels (TWh)', \n 'Electricity from nuclear (TWh)', 'Electricity from renewables (TWh)']].copy()\n \n df_top3.columns = ['Year', 'Entity', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n df_top3,\n id_vars=['Year', 'Entity'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Entity, Year, and Energy Source\n transformed_df = transformed_df.sort_values(['Entity', 'Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-81", "resultTableId": "table-10", "chart": {"id": "chart-1760739075465", "chartType": "Custom Area", "encodingMap": {"x": {"channel": "x", "bin": false, "fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"channel": "y", "bin": false, "fieldID": "concept-1760738917347"}, "x2": {}, "y2": {"channel": "y2", "bin": false}, "color": {"fieldID": "concept-1760738921927", "sortBy": "[\"Fossil Fuels\",\"Nuclear\",\"Renewables\"]"}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-81", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "show the composition of top 3 CO2 emitting countries", "displayContent": "Show **energy composition** of **top 3 CO2 emitting countries** over time"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code performs the following high-level transformations:\n\n1. **Identifies top polluters**: Calculates the total `Value_co2_emissions_kt_by_country` across all years for each `Entity` (country), then selects the **top 3** countries with the highest cumulative CO2 emissions.\n\n2. **Filters the dataset**: Retains only records for the **top 3 CO2-emitting countries** from the original energy data.\n\n3. **Simplifies column structure**: Extracts the relevant energy production columns (`Electricity from fossil fuels (TWh)`, `Electricity from nuclear (TWh)`, `Electricity from renewables (TWh)`) and renames them to **Fossil Fuels**, **Nuclear**, and **Renewables** for clarity.\n\n4. **Reshapes data to long format**: Transforms the data from wide format (separate columns for each energy source) to long format, where each row represents a specific `Year`, `Entity`, and `Energy Source` combination with its corresponding `Energy` production value.\n\n5. **Sorts the output**: Orders the final dataset by `Entity`, `Year`, and `Energy Source` for systematic presentation.", "concepts": [], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5593029.785, 5736319.824, 5738290.039, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 62.21, 63.02, 63.71, 439.73\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total CO2 emissions by country across all years\n total_co2_by_country = df_energy.groupby('Entity')['Value_co2_emissions_kt_by_country'].sum().reset_index()\n \n # Get top 3 CO2 emitting countries\n top3_countries = total_co2_by_country.nlargest(3, 'Value_co2_emissions_kt_by_country')['Entity'].tolist()\n \n # Filter data for top 3 countries\n df_top3 = df_energy[df_energy['Entity'].isin(top3_countries)].copy()\n \n # Select relevant columns and rename for clarity\n df_top3 = df_top3[['Year', 'Entity', 'Electricity from fossil fuels (TWh)', \n 'Electricity from nuclear (TWh)', 'Electricity from renewables (TWh)']].copy()\n \n df_top3.columns = ['Year', 'Entity', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n df_top3,\n id_vars=['Year', 'Entity'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Entity, Year, and Energy Source\n transformed_df = transformed_df.sort_values(['Entity', 'Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code performs the following high-level transformations:\n\n1. **Identifies top polluters**: Calculates the total `Value_co2_emissions_kt_by_country` across all years for each `Entity` (country), then selects the **top 3** countries with the highest cumulative CO2 emissions.\n\n2. **Filters the dataset**: Retains only records for the **top 3 CO2-emitting countries** from the original energy data.\n\n3. **Simplifies column structure**: Extracts the relevant energy production columns (`Electricity from fossil fuels (TWh)`, `Electricity from nuclear (TWh)`, `Electricity from renewables (TWh)`) and renames them to **Fossil Fuels**, **Nuclear**, and **Renewables** for clarity.\n\n4. **Reshapes data to long format**: Transforms the data from wide format (separate columns for each energy source) to long format, where each row represents a specific `Year`, `Entity`, and `Energy Source` combination with its corresponding `Energy` production value.\n\n5. **Sorts the output**: Orders the final dataset by `Entity`, `Year`, and `Energy Source` for systematic presentation.\n\n[CONCEPTS EXPLANATION]\n\n```json\n[]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}], "charts": [{"id": "chart-1760739084455", "chartType": "Custom Area", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-1760738917347"}, "x2": {}, "y2": {"channel": "y2", "bin": false}, "color": {"fieldID": "concept-1760738921927"}, "column": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-10", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760739021201", "chartType": "Custom Area", "encodingMap": {"x": {"channel": "x", "bin": false, "fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"channel": "y", "bin": false, "fieldID": "concept-1760738917347"}, "x2": {}, "y2": {"channel": "y2", "bin": false}, "color": {"fieldID": "concept-1760738921927", "sortBy": "[\"Fossil Fuels\",\"Nuclear\",\"Renewables\"]"}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-81", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738819387", "chartType": "Grouped Bar Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "y": {"fieldID": "concept-Renewable Percentage-1760738820889"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}, "group": {"fieldID": "original--global-energy-20-small.csv--Year"}}, "tableRef": "table-27", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738770100", "chartType": "Grouped Bar Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "y": {"fieldID": "original--global-energy-20-small.csv--Electricity from renewables (TWh)"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}, "group": {"fieldID": "original--global-energy-20-small.csv--Year"}}, "tableRef": "table-97", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738436615", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year", "sortOrder": "ascending"}, "y": {"fieldID": "concept-rank-1760738444550", "sortOrder": "descending"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-78", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738423852", "chartType": "Dotted Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-renewable_percentage-1760738424337"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-45", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738400970", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-1760738385163"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {"fieldID": "concept-1760738389404", "sortBy": "[\"fossil fuels\",\"nuclear\",\"renewables\"]"}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-82", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738355655", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "original--global-energy-20-small.csv--Value_co2_emissions_kt_by_country"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}}, "tableRef": "global-energy-20-small.csv", "saved": false, "source": "user", "unread": false}], "conceptShelfItems": [{"id": "concept-1760738921927", "name": "Energy Source", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "concept-1760738917347", "name": "Energy", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "concept-Renewable Percentage-1760738820889", "name": "Renewable Percentage", "type": "auto", "description": "", "source": "custom", "tableRef": "custom", "temporary": true}, {"id": "concept-1760738743125", "name": "Renewable Energy", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "concept-rank-1760738444550", "name": "rank", "type": "auto", "description": "", "source": "custom", "tableRef": "custom", "temporary": true}, {"id": "concept-renewable_percentage-1760738424337", "name": "renewable_percentage", "type": "auto", "description": "", "source": "custom", "tableRef": "custom", "temporary": true}, {"id": "concept-1760738389404", "name": "source", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "concept-1760738385163", "name": "energy", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "original--global-energy-20-small.csv--Year", "name": "Year", "type": "integer", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Entity", "name": "Entity", "type": "string", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Value_co2_emissions_kt_by_country", "name": "Value_co2_emissions_kt_by_country", "type": "number", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Electricity from fossil fuels (TWh)", "name": "Electricity from fossil fuels (TWh)", "type": "number", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Electricity from nuclear (TWh)", "name": "Electricity from nuclear (TWh)", "type": "number", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Electricity from renewables (TWh)", "name": "Electricity from renewables (TWh)", "type": "number", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}], "messages": [{"timestamp": 1760831081885, "type": "success", "component": "data formulator", "value": "Successfully loaded Global Energy"}], "displayedMessageIdx": 0, "viewMode": "report", "chartSynthesisInProgress": [], "config": {"formulateTimeoutSeconds": 60, "maxRepairAttempts": 1, "defaultChartWidth": 300, "defaultChartHeight": 300}, "dataCleanBlocks": [], "cleanInProgress": false, "generatedReports": [{"id": "report-1760831156182-8277", "content": "# Global Renewable Energy Shift: 2000 to 2020\n\nBetween 2000 and 2020, the world witnessed a notable transformation in renewable energy adoption. Global renewable electricity nearly doubled from 16% to 29% of total generation, signaling meaningful progress in the energy transition.\n\n[IMAGE(chart-1760738819387)]\n\nThe data reveals striking regional variations. Brazil maintained renewable leadership above 84%, while countries like Australia, Germany, and Italy dramatically expanded their renewable capacity—Australia tripling from 9% to 26%. However, some nations like Mexico experienced declining renewable shares, highlighting uneven progress across different energy systems.\n\n**In summary**, while the 20-year period shows encouraging momentum toward cleaner energy, the pace and direction vary significantly by country, suggesting that achieving global renewable energy goals will require sustained, coordinated efforts tailored to each nation's unique energy landscape and policy environment.", "style": "short note", "selectedChartIds": ["chart-1760738819387"], "createdAt": 1760831163718, "status": "completed", "title": "Global Renewable Energy Shift: 2000 to 2020", "anchorChartId": "chart-1760738819387"}, {"id": "report-1760831130105-4063", "content": "# The Global Renewable Energy Revolution: Two Decades of Transformation\n\nThe world's energy landscape has undergone a remarkable transformation between 2000 and 2020, with renewable electricity generation emerging as a critical component of the global energy mix. This shift reflects both technological advancement and growing commitment to sustainable energy solutions.\n\n[IMAGE(chart-1760738770100)]\n\nLooking at renewable energy adoption across major economies, the growth has been nothing short of extraordinary. China leads the pack with a staggering increase from 225.56 TWh in 2000 to 2,184.94 TWh in 2020—nearly a tenfold expansion. The United States more than doubled its renewable output from 335.45 TWh to 821.40 TWh, while Brazil grew from 308.77 TWh to 520.01 TWh. Notably, countries like Australia, India, and Germany also demonstrated significant gains, with Australia jumping from just 17.11 TWh to 63.99 TWh during this period.\n\n[IMAGE(chart-1760739084455)]\n\nWhen examining the energy portfolios of the three largest CO2 emitters—China, India, and the United States—a complex picture emerges. While China's total energy consumption has grown exponentially, with fossil fuels still dominating, the renewable sector (shown in red) has expanded substantially. The United States shows a more stable total energy consumption, with renewables gradually claiming a larger share. India's energy growth, though significant, remains heavily reliant on fossil fuels, though renewable adoption is accelerating.\n\n**In summary**, the past two decades reveal a global energy transition in progress. While renewable energy has achieved impressive growth worldwide, fossil fuels continue to dominate electricity generation in major economies. Key questions remain: Can this momentum accelerate sufficiently to meet climate goals? What policies will drive faster renewable adoption in emerging economies?", "style": "blog post", "selectedChartIds": ["chart-1760739084455", "chart-1760738770100"], "createdAt": 1760831142289, "status": "completed", "title": "The Global Renewable Energy Revolution: Two Decades of Transformation", "anchorChartId": "chart-1760739084455"}, {"id": "report-1760831094231-2424", "content": "# Global Renewable Energy: A Tale of Leaders and Laggards\n\nThe global energy landscape has undergone significant transformation over the past two decades, with renewable energy emerging as a critical player in the electricity mix. Analyzing data from 21 major economies between 2000 and 2020 reveals striking disparities in how nations have embraced clean energy alternatives.\n\n[IMAGE(chart-1760738423852)]\n\nThe first visualization reveals a fascinating divergence in renewable energy adoption. **Brazil** stands out as a consistent leader, maintaining renewable electricity percentages between 75-90% throughout the entire period, thanks largely to its robust hydroelectric infrastructure. **Canada** follows a similar trajectory, steadily increasing from about 60% to nearly 70% by 2020. Meanwhile, **Germany, Spain, Italy, and the United Kingdom** show remarkable growth trajectories, climbing from under 20% in the early 2000s to over 40% by 2020—demonstrating that nations can dramatically reshape their energy portfolios within two decades.\n\nOn the opposite end of the spectrum, **South Africa** remains nearly flat at the bottom, showing minimal renewable adoption despite global trends. **Saudi Arabia** and **Poland** also lag significantly, though both show modest upticks in recent years.\n\n[IMAGE(chart-1760738436615)]\n\nThe ranking chart illustrates the competitive dynamics of renewable energy leadership. **Brazil and Canada** maintain their dominance at ranks 1-2 throughout most years, while European nations like **Germany, Spain, and the UK** engage in a dynamic competition for the 3rd-5th positions, particularly after 2010. The volatility in middle rankings reflects the rapid changes in energy policy and investment across different nations, with countries like **China** climbing from lower ranks to break into the top 7 by 2020.\n\n**In summary**, the data reveals a bifurcated global energy transition: a group of progressive nations have successfully scaled renewable electricity to 40-90% of their mix, while others remain heavily dependent on fossil fuels. These patterns suggest that political will, natural resource endowment, and infrastructure investment are key determinants of renewable energy success. Important follow-up questions include: What policy mechanisms enabled top performers to achieve such high renewable percentages? Can lagging nations replicate these successes, or do geographic and economic constraints create insurmountable barriers?", "style": "blog post", "selectedChartIds": ["chart-1760738423852", "chart-1760738436615"], "createdAt": 1760831110064, "status": "completed", "title": "Global Renewable Energy: A Tale of Leaders and Laggards", "anchorChartId": "chart-1760738423852"}], "currentReport": {"id": "report-1760750575650-2619", "content": "# Hollywood's Billion-Dollar Hitmakers\n\n*Avatar* stands alone—earning over $2.5B in profit, dwarfing all competition. Action and Adventure films dominate the most profitable titles, with franchises like *Jurassic Park*, *The Dark Knight*, and *Lord of the Rings* proving blockbuster formulas work.\n\n\n\nSteven Spielberg leads all directors with $7.2B in total profit across his career, showcasing remarkable consistency with hits spanning decades—from *Jurassic Park* to *E.T.* His nearest competitors trail by billions, underlining his unmatched commercial impact.\n\n\n\n**In summary**, mega-budget Action and Adventure films generate extraordinary returns when they succeed, and a handful of elite directors—led by Spielberg—have mastered the formula for sustained box office dominance.", "style": "short note", "selectedChartIds": ["chart-1760743347871", "chart-1760743768741"], "chartImages": {}, "createdAt": 1760750584189, "title": "Report - 10/17/2025"}, "activeChallenges": [], "_persist": {"version": -1, "rehydrated": true}, "draftNodes": [], "focusedId": {"type": "report", "reportId": "report-1760831156182-8277"}}
\ No newline at end of file
+{"tables": [{"kind": "table", "id": "global-energy-20-small.csv", "displayId": "energy-co2", "names": ["Year", "Entity", "Value_co2_emissions_kt_by_country", "Electricity from fossil fuels (TWh)", "Electricity from nuclear (TWh)", "Electricity from renewables (TWh)"], "metadata": {"Year": {"type": "number", "semanticType": "Year"}, "Entity": {"type": "string", "semanticType": "Location"}, "Value_co2_emissions_kt_by_country": {"type": "number", "semanticType": "Number"}, "Electricity from fossil fuels (TWh)": {"type": "number", "semanticType": "Number"}, "Electricity from nuclear (TWh)": {"type": "number", "semanticType": "Number"}, "Electricity from renewables (TWh)": {"type": "number", "semanticType": "Number"}}, "rows": [{"Year": 2000, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 339450, "Electricity from fossil fuels (TWh)": 181.05, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 17.11}, {"Year": 2001, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 345640, "Electricity from fossil fuels (TWh)": 194.33, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 17.4}, {"Year": 2002, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 353369.9951, "Electricity from fossil fuels (TWh)": 197.29, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 17.35}, {"Year": 2003, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 352579.9866, "Electricity from fossil fuels (TWh)": 195.13, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 18.5}, {"Year": 2004, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 365809.9976, "Electricity from fossil fuels (TWh)": 203.66, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 19.41}, {"Year": 2005, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 370089.9963, "Electricity from fossil fuels (TWh)": 195.95, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 19.75}, {"Year": 2006, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 375489.9902, "Electricity from fossil fuels (TWh)": 198.72, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 21.19}, {"Year": 2007, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 385750, "Electricity from fossil fuels (TWh)": 208.59, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 20.93}, {"Year": 2008, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 388940.0024, "Electricity from fossil fuels (TWh)": 211.06, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 18.49}, {"Year": 2009, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 395290.0085, "Electricity from fossil fuels (TWh)": 216.42, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 18.32}, {"Year": 2010, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 387540.0085, "Electricity from fossil fuels (TWh)": 212.5, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 21.13}, {"Year": 2011, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 386380.0049, "Electricity from fossil fuels (TWh)": 213.56, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 27.33}, {"Year": 2012, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 386970.0012, "Electricity from fossil fuels (TWh)": 206.75, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 26.63}, {"Year": 2013, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 380279.9988, "Electricity from fossil fuels (TWh)": 195.78, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 34.2}, {"Year": 2014, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 371630.0049, "Electricity from fossil fuels (TWh)": 205.46, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 36.15}, {"Year": 2015, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 377799.9878, "Electricity from fossil fuels (TWh)": 197.72, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 33.12}, {"Year": 2016, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 384989.9902, "Electricity from fossil fuels (TWh)": 207.66, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 38.41}, {"Year": 2017, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 389160.0037, "Electricity from fossil fuels (TWh)": 209.14, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 40.77}, {"Year": 2018, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 387070.0073, "Electricity from fossil fuels (TWh)": 207.45, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 42.93}, {"Year": 2019, "Entity": "Australia", "Value_co2_emissions_kt_by_country": 386529.9988, "Electricity from fossil fuels (TWh)": 196.45, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 53.41}, {"Year": 2020, "Entity": "Australia", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 186.92, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 63.99}, {"Year": 2000, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 313670, "Electricity from fossil fuels (TWh)": 28.87, "Electricity from nuclear (TWh)": 4.94, "Electricity from renewables (TWh)": 308.77}, {"Year": 2001, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 319380, "Electricity from fossil fuels (TWh)": 35.19, "Electricity from nuclear (TWh)": 14.27, "Electricity from renewables (TWh)": 273.71}, {"Year": 2002, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 317760.0098, "Electricity from fossil fuels (TWh)": 33.5, "Electricity from nuclear (TWh)": 13.84, "Electricity from renewables (TWh)": 292.95}, {"Year": 2003, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 310809.9976, "Electricity from fossil fuels (TWh)": 31.62, "Electricity from nuclear (TWh)": 13.4, "Electricity from renewables (TWh)": 313.88}, {"Year": 2004, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 328519.989, "Electricity from fossil fuels (TWh)": 40.14, "Electricity from nuclear (TWh)": 11.6, "Electricity from renewables (TWh)": 329.43}, {"Year": 2005, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 331690.0024, "Electricity from fossil fuels (TWh)": 39.56, "Electricity from nuclear (TWh)": 9.2, "Electricity from renewables (TWh)": 346.96}, {"Year": 2006, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 335619.9951, "Electricity from fossil fuels (TWh)": 39.4, "Electricity from nuclear (TWh)": 12.98, "Electricity from renewables (TWh)": 359.55}, {"Year": 2007, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 352559.9976, "Electricity from fossil fuels (TWh)": 37.64, "Electricity from nuclear (TWh)": 11.65, "Electricity from renewables (TWh)": 387.88}, {"Year": 2008, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 373630.0049, "Electricity from fossil fuels (TWh)": 55.87, "Electricity from nuclear (TWh)": 13.21, "Electricity from renewables (TWh)": 385.61}, {"Year": 2009, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 350000, "Electricity from fossil fuels (TWh)": 36.32, "Electricity from nuclear (TWh)": 12.22, "Electricity from renewables (TWh)": 410.13}, {"Year": 2010, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 397929.9927, "Electricity from fossil fuels (TWh)": 61.02, "Electricity from nuclear (TWh)": 13.77, "Electricity from renewables (TWh)": 435.99}, {"Year": 2011, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 418309.9976, "Electricity from fossil fuels (TWh)": 50.27, "Electricity from nuclear (TWh)": 14.8, "Electricity from renewables (TWh)": 462.32}, {"Year": 2012, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 454230.011, "Electricity from fossil fuels (TWh)": 77.21, "Electricity from nuclear (TWh)": 15.17, "Electricity from renewables (TWh)": 454.78}, {"Year": 2013, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 486839.9963, "Electricity from fossil fuels (TWh)": 112, "Electricity from nuclear (TWh)": 14.65, "Electricity from renewables (TWh)": 436.84}, {"Year": 2014, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 511619.9951, "Electricity from fossil fuels (TWh)": 136.58, "Electricity from nuclear (TWh)": 14.46, "Electricity from renewables (TWh)": 430.82}, {"Year": 2015, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 485339.9963, "Electricity from fossil fuels (TWh)": 128.85, "Electricity from nuclear (TWh)": 13.91, "Electricity from renewables (TWh)": 428.81}, {"Year": 2016, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 447079.9866, "Electricity from fossil fuels (TWh)": 93.06, "Electricity from nuclear (TWh)": 14.97, "Electricity from renewables (TWh)": 463.37}, {"Year": 2017, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 456489.9902, "Electricity from fossil fuels (TWh)": 101.9, "Electricity from nuclear (TWh)": 14.86, "Electricity from renewables (TWh)": 464.4}, {"Year": 2018, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 433989.9902, "Electricity from fossil fuels (TWh)": 86.69, "Electricity from nuclear (TWh)": 14.79, "Electricity from renewables (TWh)": 492.66}, {"Year": 2019, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": 434299.9878, "Electricity from fossil fuels (TWh)": 90.91, "Electricity from nuclear (TWh)": 15.16, "Electricity from renewables (TWh)": 512.59}, {"Year": 2020, "Entity": "Brazil", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 81.15, "Electricity from nuclear (TWh)": 13.21, "Electricity from renewables (TWh)": 520.01}, {"Year": 2000, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 514220, "Electricity from fossil fuels (TWh)": 155.56, "Electricity from nuclear (TWh)": 69.16, "Electricity from renewables (TWh)": 363.7}, {"Year": 2001, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 506620, "Electricity from fossil fuels (TWh)": 159.93, "Electricity from nuclear (TWh)": 72.86, "Electricity from renewables (TWh)": 339.58}, {"Year": 2002, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 524349.9756, "Electricity from fossil fuels (TWh)": 155.12, "Electricity from nuclear (TWh)": 71.75, "Electricity from renewables (TWh)": 357.06}, {"Year": 2003, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 544539.978, "Electricity from fossil fuels (TWh)": 157.35, "Electricity from nuclear (TWh)": 71.15, "Electricity from renewables (TWh)": 343.88}, {"Year": 2004, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 536419.9829, "Electricity from fossil fuels (TWh)": 148.86, "Electricity from nuclear (TWh)": 85.87, "Electricity from renewables (TWh)": 347.68}, {"Year": 2005, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 549030.0293, "Electricity from fossil fuels (TWh)": 150.78, "Electricity from nuclear (TWh)": 86.83, "Electricity from renewables (TWh)": 368.86}, {"Year": 2006, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 540530.0293, "Electricity from fossil fuels (TWh)": 139.71, "Electricity from nuclear (TWh)": 92.44, "Electricity from renewables (TWh)": 360.48}, {"Year": 2007, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 571630.0049, "Electricity from fossil fuels (TWh)": 149.36, "Electricity from nuclear (TWh)": 88.19, "Electricity from renewables (TWh)": 375.42}, {"Year": 2008, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 550469.9707, "Electricity from fossil fuels (TWh)": 141.33, "Electricity from nuclear (TWh)": 88.3, "Electricity from renewables (TWh)": 385.21}, {"Year": 2009, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 521320.0073, "Electricity from fossil fuels (TWh)": 129.76, "Electricity from nuclear (TWh)": 85.13, "Electricity from renewables (TWh)": 380.24}, {"Year": 2010, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 537010.0098, "Electricity from fossil fuels (TWh)": 130.08, "Electricity from nuclear (TWh)": 85.53, "Electricity from renewables (TWh)": 366.21}, {"Year": 2011, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 549289.978, "Electricity from fossil fuels (TWh)": 131.3, "Electricity from nuclear (TWh)": 88.29, "Electricity from renewables (TWh)": 391.95}, {"Year": 2012, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 546210.022, "Electricity from fossil fuels (TWh)": 124.2, "Electricity from nuclear (TWh)": 89.49, "Electricity from renewables (TWh)": 398.58}, {"Year": 2013, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 555659.9731, "Electricity from fossil fuels (TWh)": 122.87, "Electricity from nuclear (TWh)": 97.58, "Electricity from renewables (TWh)": 417.28}, {"Year": 2014, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 561679.9927, "Electricity from fossil fuels (TWh)": 122.75, "Electricity from nuclear (TWh)": 101.21, "Electricity from renewables (TWh)": 412.13}, {"Year": 2015, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 558700.0122, "Electricity from fossil fuels (TWh)": 125.7, "Electricity from nuclear (TWh)": 96.05, "Electricity from renewables (TWh)": 417.2}, {"Year": 2016, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 556830.0171, "Electricity from fossil fuels (TWh)": 122.35, "Electricity from nuclear (TWh)": 95.69, "Electricity from renewables (TWh)": 426.84}, {"Year": 2017, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 568080.0171, "Electricity from fossil fuels (TWh)": 113.7, "Electricity from nuclear (TWh)": 95.57, "Electricity from renewables (TWh)": 435.43}, {"Year": 2018, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 580090.0269, "Electricity from fossil fuels (TWh)": 112.47, "Electricity from nuclear (TWh)": 95.03, "Electricity from renewables (TWh)": 428.39}, {"Year": 2019, "Entity": "Canada", "Value_co2_emissions_kt_by_country": 580210.022, "Electricity from fossil fuels (TWh)": 110.65, "Electricity from nuclear (TWh)": 95.47, "Electricity from renewables (TWh)": 421.8}, {"Year": 2020, "Entity": "Canada", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 102.19, "Electricity from nuclear (TWh)": 92.65, "Electricity from renewables (TWh)": 429.24}, {"Year": 2000, "Entity": "China", "Value_co2_emissions_kt_by_country": 3346530, "Electricity from fossil fuels (TWh)": 1113.3, "Electricity from nuclear (TWh)": 16.74, "Electricity from renewables (TWh)": 225.56}, {"Year": 2001, "Entity": "China", "Value_co2_emissions_kt_by_country": 3529080, "Electricity from fossil fuels (TWh)": 1182.59, "Electricity from nuclear (TWh)": 17.47, "Electricity from renewables (TWh)": 280.73}, {"Year": 2002, "Entity": "China", "Value_co2_emissions_kt_by_country": 3810060.059, "Electricity from fossil fuels (TWh)": 1337.46, "Electricity from nuclear (TWh)": 25.13, "Electricity from renewables (TWh)": 291.41}, {"Year": 2003, "Entity": "China", "Value_co2_emissions_kt_by_country": 4415910.156, "Electricity from fossil fuels (TWh)": 1579.96, "Electricity from nuclear (TWh)": 43.34, "Electricity from renewables (TWh)": 287.28}, {"Year": 2004, "Entity": "China", "Value_co2_emissions_kt_by_country": 5124819.824, "Electricity from fossil fuels (TWh)": 1795.41, "Electricity from nuclear (TWh)": 50.47, "Electricity from renewables (TWh)": 357.43}, {"Year": 2005, "Entity": "China", "Value_co2_emissions_kt_by_country": 5824629.883, "Electricity from fossil fuels (TWh)": 2042.8, "Electricity from nuclear (TWh)": 53.09, "Electricity from renewables (TWh)": 404.37}, {"Year": 2006, "Entity": "China", "Value_co2_emissions_kt_by_country": 6437470.215, "Electricity from fossil fuels (TWh)": 2364.16, "Electricity from nuclear (TWh)": 54.84, "Electricity from renewables (TWh)": 446.72}, {"Year": 2007, "Entity": "China", "Value_co2_emissions_kt_by_country": 6993180.176, "Electricity from fossil fuels (TWh)": 2718.7, "Electricity from nuclear (TWh)": 62.13, "Electricity from renewables (TWh)": 500.71}, {"Year": 2008, "Entity": "China", "Value_co2_emissions_kt_by_country": 7199600.098, "Electricity from fossil fuels (TWh)": 2762.29, "Electricity from nuclear (TWh)": 68.39, "Electricity from renewables (TWh)": 665.08}, {"Year": 2009, "Entity": "China", "Value_co2_emissions_kt_by_country": 7719069.824, "Electricity from fossil fuels (TWh)": 2980.2, "Electricity from nuclear (TWh)": 70.05, "Electricity from renewables (TWh)": 664.39}, {"Year": 2010, "Entity": "China", "Value_co2_emissions_kt_by_country": 8474919.922, "Electricity from fossil fuels (TWh)": 3326.19, "Electricity from nuclear (TWh)": 74.74, "Electricity from renewables (TWh)": 786.38}, {"Year": 2011, "Entity": "China", "Value_co2_emissions_kt_by_country": 9282549.805, "Electricity from fossil fuels (TWh)": 3811.77, "Electricity from nuclear (TWh)": 87.2, "Electricity from renewables (TWh)": 792.38}, {"Year": 2012, "Entity": "China", "Value_co2_emissions_kt_by_country": 9541870.117, "Electricity from fossil fuels (TWh)": 3869.38, "Electricity from nuclear (TWh)": 98.32, "Electricity from renewables (TWh)": 999.56}, {"Year": 2013, "Entity": "China", "Value_co2_emissions_kt_by_country": 9984570.313, "Electricity from fossil fuels (TWh)": 4203.77, "Electricity from nuclear (TWh)": 111.5, "Electricity from renewables (TWh)": 1093.37}, {"Year": 2014, "Entity": "China", "Value_co2_emissions_kt_by_country": 10006669.92, "Electricity from fossil fuels (TWh)": 4345.86, "Electricity from nuclear (TWh)": 133.22, "Electricity from renewables (TWh)": 1289.23}, {"Year": 2015, "Entity": "China", "Value_co2_emissions_kt_by_country": 9861099.609, "Electricity from fossil fuels (TWh)": 4222.76, "Electricity from nuclear (TWh)": 171.38, "Electricity from renewables (TWh)": 1393.66}, {"Year": 2016, "Entity": "China", "Value_co2_emissions_kt_by_country": 9874660.156, "Electricity from fossil fuels (TWh)": 4355, "Electricity from nuclear (TWh)": 213.18, "Electricity from renewables (TWh)": 1522.79}, {"Year": 2017, "Entity": "China", "Value_co2_emissions_kt_by_country": 10096009.77, "Electricity from fossil fuels (TWh)": 4643.1, "Electricity from nuclear (TWh)": 248.1, "Electricity from renewables (TWh)": 1667.06}, {"Year": 2018, "Entity": "China", "Value_co2_emissions_kt_by_country": 10502929.69, "Electricity from fossil fuels (TWh)": 4990.28, "Electricity from nuclear (TWh)": 295, "Electricity from renewables (TWh)": 1835.32}, {"Year": 2019, "Entity": "China", "Value_co2_emissions_kt_by_country": 10707219.73, "Electricity from fossil fuels (TWh)": 5098.22, "Electricity from nuclear (TWh)": 348.7, "Electricity from renewables (TWh)": 2014.57}, {"Year": 2020, "Entity": "China", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 5184.13, "Electricity from nuclear (TWh)": 366.2, "Electricity from renewables (TWh)": 2184.94}, {"Year": 2000, "Entity": "France", "Value_co2_emissions_kt_by_country": 373120, "Electricity from fossil fuels (TWh)": 50.61, "Electricity from nuclear (TWh)": 415.16, "Electricity from renewables (TWh)": 67.83}, {"Year": 2001, "Entity": "France", "Value_co2_emissions_kt_by_country": 376730, "Electricity from fossil fuels (TWh)": 46.48, "Electricity from nuclear (TWh)": 421.08, "Electricity from renewables (TWh)": 76.09}, {"Year": 2002, "Entity": "France", "Value_co2_emissions_kt_by_country": 371019.989, "Electricity from fossil fuels (TWh)": 52.67, "Electricity from nuclear (TWh)": 436.76, "Electricity from renewables (TWh)": 62.69}, {"Year": 2003, "Entity": "France", "Value_co2_emissions_kt_by_country": 376709.9915, "Electricity from fossil fuels (TWh)": 57.38, "Electricity from nuclear (TWh)": 441.07, "Electricity from renewables (TWh)": 61.47}, {"Year": 2004, "Entity": "France", "Value_co2_emissions_kt_by_country": 377790.0085, "Electricity from fossil fuels (TWh)": 56.53, "Electricity from nuclear (TWh)": 448.24, "Electricity from renewables (TWh)": 62.42}, {"Year": 2005, "Entity": "France", "Value_co2_emissions_kt_by_country": 380660.0037, "Electricity from fossil fuels (TWh)": 63.35, "Electricity from nuclear (TWh)": 451.53, "Electricity from renewables (TWh)": 54.98}, {"Year": 2006, "Entity": "France", "Value_co2_emissions_kt_by_country": 371549.9878, "Electricity from fossil fuels (TWh)": 56.9, "Electricity from nuclear (TWh)": 450.19, "Electricity from renewables (TWh)": 60.91}, {"Year": 2007, "Entity": "France", "Value_co2_emissions_kt_by_country": 362829.9866, "Electricity from fossil fuels (TWh)": 58.18, "Electricity from nuclear (TWh)": 439.73, "Electricity from renewables (TWh)": 64.3}, {"Year": 2008, "Entity": "France", "Value_co2_emissions_kt_by_country": 357989.9902, "Electricity from fossil fuels (TWh)": 55.57, "Electricity from nuclear (TWh)": 439.45, "Electricity from renewables (TWh)": 72.33}, {"Year": 2009, "Entity": "France", "Value_co2_emissions_kt_by_country": 343730.011, "Electricity from fossil fuels (TWh)": 51.32, "Electricity from nuclear (TWh)": 409.74, "Electricity from renewables (TWh)": 68.15}, {"Year": 2010, "Entity": "France", "Value_co2_emissions_kt_by_country": 347779.9988, "Electricity from fossil fuels (TWh)": 57.63, "Electricity from nuclear (TWh)": 428.52, "Electricity from renewables (TWh)": 76.68}, {"Year": 2011, "Entity": "France", "Value_co2_emissions_kt_by_country": 335140.0146, "Electricity from fossil fuels (TWh)": 58.99, "Electricity from nuclear (TWh)": 442.39, "Electricity from renewables (TWh)": 66.02}, {"Year": 2012, "Entity": "France", "Value_co2_emissions_kt_by_country": 338420.0134, "Electricity from fossil fuels (TWh)": 56.42, "Electricity from nuclear (TWh)": 425.41, "Electricity from renewables (TWh)": 85.25}, {"Year": 2013, "Entity": "France", "Value_co2_emissions_kt_by_country": 338559.9976, "Electricity from fossil fuels (TWh)": 53.35, "Electricity from nuclear (TWh)": 423.68, "Electricity from renewables (TWh)": 99.42}, {"Year": 2014, "Entity": "France", "Value_co2_emissions_kt_by_country": 306100.0061, "Electricity from fossil fuels (TWh)": 35.68, "Electricity from nuclear (TWh)": 436.48, "Electricity from renewables (TWh)": 94.03}, {"Year": 2015, "Entity": "France", "Value_co2_emissions_kt_by_country": 311299.9878, "Electricity from fossil fuels (TWh)": 44.65, "Electricity from nuclear (TWh)": 437.43, "Electricity from renewables (TWh)": 91.84}, {"Year": 2016, "Entity": "France", "Value_co2_emissions_kt_by_country": 313920.0134, "Electricity from fossil fuels (TWh)": 56.45, "Electricity from nuclear (TWh)": 403.2, "Electricity from renewables (TWh)": 99}, {"Year": 2017, "Entity": "France", "Value_co2_emissions_kt_by_country": 317829.9866, "Electricity from fossil fuels (TWh)": 65.09, "Electricity from nuclear (TWh)": 398.36, "Electricity from renewables (TWh)": 92.63}, {"Year": 2018, "Entity": "France", "Value_co2_emissions_kt_by_country": 307049.9878, "Electricity from fossil fuels (TWh)": 49.27, "Electricity from nuclear (TWh)": 412.94, "Electricity from renewables (TWh)": 113.62}, {"Year": 2019, "Entity": "France", "Value_co2_emissions_kt_by_country": 300519.989, "Electricity from fossil fuels (TWh)": 53.5, "Electricity from nuclear (TWh)": 399.01, "Electricity from renewables (TWh)": 113.21}, {"Year": 2020, "Entity": "France", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 48.14, "Electricity from nuclear (TWh)": 353.83, "Electricity from renewables (TWh)": 125.28}, {"Year": 2000, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 830280, "Electricity from fossil fuels (TWh)": 367.22, "Electricity from nuclear (TWh)": 169.61, "Electricity from renewables (TWh)": 35.47}, {"Year": 2001, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 847680, "Electricity from fossil fuels (TWh)": 372.69, "Electricity from nuclear (TWh)": 171.3, "Electricity from renewables (TWh)": 37.9}, {"Year": 2002, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 833380.0049, "Electricity from fossil fuels (TWh)": 372.64, "Electricity from nuclear (TWh)": 164.84, "Electricity from renewables (TWh)": 44.48}, {"Year": 2003, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 836789.978, "Electricity from fossil fuels (TWh)": 390.81, "Electricity from nuclear (TWh)": 165.06, "Electricity from renewables (TWh)": 46.67}, {"Year": 2004, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 821070.0073, "Electricity from fossil fuels (TWh)": 385.24, "Electricity from nuclear (TWh)": 167.07, "Electricity from renewables (TWh)": 57.97}, {"Year": 2005, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 802380.0049, "Electricity from fossil fuels (TWh)": 386.96, "Electricity from nuclear (TWh)": 163.05, "Electricity from renewables (TWh)": 63.4}, {"Year": 2006, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 814409.9731, "Electricity from fossil fuels (TWh)": 390.03, "Electricity from nuclear (TWh)": 167.27, "Electricity from renewables (TWh)": 72.51}, {"Year": 2007, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 783799.9878, "Electricity from fossil fuels (TWh)": 402.4, "Electricity from nuclear (TWh)": 140.53, "Electricity from renewables (TWh)": 89.38}, {"Year": 2008, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 789690.0024, "Electricity from fossil fuels (TWh)": 390.43, "Electricity from nuclear (TWh)": 148.49, "Electricity from renewables (TWh)": 94.28}, {"Year": 2009, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 734809.9976, "Electricity from fossil fuels (TWh)": 358.07, "Electricity from nuclear (TWh)": 134.93, "Electricity from renewables (TWh)": 95.94}, {"Year": 2010, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 773070.0073, "Electricity from fossil fuels (TWh)": 378.9, "Electricity from nuclear (TWh)": 140.56, "Electricity from renewables (TWh)": 105.18}, {"Year": 2011, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 746479.9805, "Electricity from fossil fuels (TWh)": 373.16, "Electricity from nuclear (TWh)": 107.97, "Electricity from renewables (TWh)": 124.04}, {"Year": 2012, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 760130.0049, "Electricity from fossil fuels (TWh)": 377.89, "Electricity from nuclear (TWh)": 99.46, "Electricity from renewables (TWh)": 143.04}, {"Year": 2013, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 776150.0244, "Electricity from fossil fuels (TWh)": 381.52, "Electricity from nuclear (TWh)": 97.29, "Electricity from renewables (TWh)": 152.34}, {"Year": 2014, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 736010.0098, "Electricity from fossil fuels (TWh)": 360.28, "Electricity from nuclear (TWh)": 97.13, "Electricity from renewables (TWh)": 162.54}, {"Year": 2015, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 742309.9976, "Electricity from fossil fuels (TWh)": 359.99, "Electricity from nuclear (TWh)": 91.79, "Electricity from renewables (TWh)": 188.79}, {"Year": 2016, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 747150.0244, "Electricity from fossil fuels (TWh)": 368.67, "Electricity from nuclear (TWh)": 84.63, "Electricity from renewables (TWh)": 189.67}, {"Year": 2017, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 732200.0122, "Electricity from fossil fuels (TWh)": 353.37, "Electricity from nuclear (TWh)": 76.32, "Electricity from renewables (TWh)": 216.32}, {"Year": 2018, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 707700.0122, "Electricity from fossil fuels (TWh)": 334.65, "Electricity from nuclear (TWh)": 76, "Electricity from renewables (TWh)": 222.07}, {"Year": 2019, "Entity": "Germany", "Value_co2_emissions_kt_by_country": 657400.0244, "Electricity from fossil fuels (TWh)": 284.09, "Electricity from nuclear (TWh)": 75.07, "Electricity from renewables (TWh)": 240.33}, {"Year": 2020, "Entity": "Germany", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 251.4, "Electricity from nuclear (TWh)": 64.38, "Electricity from renewables (TWh)": 251.48}, {"Year": 2000, "Entity": "India", "Value_co2_emissions_kt_by_country": 937860, "Electricity from fossil fuels (TWh)": 475.35, "Electricity from nuclear (TWh)": 15.77, "Electricity from renewables (TWh)": 80.27}, {"Year": 2001, "Entity": "India", "Value_co2_emissions_kt_by_country": 953540, "Electricity from fossil fuels (TWh)": 491.01, "Electricity from nuclear (TWh)": 18.89, "Electricity from renewables (TWh)": 76.19}, {"Year": 2002, "Entity": "India", "Value_co2_emissions_kt_by_country": 985450.0122, "Electricity from fossil fuels (TWh)": 517.51, "Electricity from nuclear (TWh)": 19.35, "Electricity from renewables (TWh)": 72.78}, {"Year": 2003, "Entity": "India", "Value_co2_emissions_kt_by_country": 1011770.02, "Electricity from fossil fuels (TWh)": 545.36, "Electricity from nuclear (TWh)": 18.14, "Electricity from renewables (TWh)": 74.63}, {"Year": 2004, "Entity": "India", "Value_co2_emissions_kt_by_country": 1085670.044, "Electricity from fossil fuels (TWh)": 567.86, "Electricity from nuclear (TWh)": 21.26, "Electricity from renewables (TWh)": 109.2}, {"Year": 2005, "Entity": "India", "Value_co2_emissions_kt_by_country": 1136469.971, "Electricity from fossil fuels (TWh)": 579.32, "Electricity from nuclear (TWh)": 17.73, "Electricity from renewables (TWh)": 107.47}, {"Year": 2006, "Entity": "India", "Value_co2_emissions_kt_by_country": 1215209.961, "Electricity from fossil fuels (TWh)": 599.24, "Electricity from nuclear (TWh)": 17.63, "Electricity from renewables (TWh)": 127.56}, {"Year": 2007, "Entity": "India", "Value_co2_emissions_kt_by_country": 1336739.99, "Electricity from fossil fuels (TWh)": 636.68, "Electricity from nuclear (TWh)": 17.83, "Electricity from renewables (TWh)": 141.75}, {"Year": 2008, "Entity": "India", "Value_co2_emissions_kt_by_country": 1424380.005, "Electricity from fossil fuels (TWh)": 674.27, "Electricity from nuclear (TWh)": 15.23, "Electricity from renewables (TWh)": 138.91}, {"Year": 2009, "Entity": "India", "Value_co2_emissions_kt_by_country": 1564880.005, "Electricity from fossil fuels (TWh)": 728.56, "Electricity from nuclear (TWh)": 16.82, "Electricity from renewables (TWh)": 134.33}, {"Year": 2010, "Entity": "India", "Value_co2_emissions_kt_by_country": 1659979.98, "Electricity from fossil fuels (TWh)": 771.78, "Electricity from nuclear (TWh)": 23.08, "Electricity from renewables (TWh)": 142.61}, {"Year": 2011, "Entity": "India", "Value_co2_emissions_kt_by_country": 1756739.99, "Electricity from fossil fuels (TWh)": 828.16, "Electricity from nuclear (TWh)": 32.22, "Electricity from renewables (TWh)": 173.62}, {"Year": 2012, "Entity": "India", "Value_co2_emissions_kt_by_country": 1909439.941, "Electricity from fossil fuels (TWh)": 893.45, "Electricity from nuclear (TWh)": 33.14, "Electricity from renewables (TWh)": 165.25}, {"Year": 2013, "Entity": "India", "Value_co2_emissions_kt_by_country": 1972430.054, "Electricity from fossil fuels (TWh)": 924.93, "Electricity from nuclear (TWh)": 33.31, "Electricity from renewables (TWh)": 187.9}, {"Year": 2014, "Entity": "India", "Value_co2_emissions_kt_by_country": 2147110.107, "Electricity from fossil fuels (TWh)": 1025.29, "Electricity from nuclear (TWh)": 34.69, "Electricity from renewables (TWh)": 202.04}, {"Year": 2015, "Entity": "India", "Value_co2_emissions_kt_by_country": 2158020.02, "Electricity from fossil fuels (TWh)": 1080.44, "Electricity from nuclear (TWh)": 38.31, "Electricity from renewables (TWh)": 203.21}, {"Year": 2016, "Entity": "India", "Value_co2_emissions_kt_by_country": 2195250, "Electricity from fossil fuels (TWh)": 1155.52, "Electricity from nuclear (TWh)": 37.9, "Electricity from renewables (TWh)": 208.21}, {"Year": 2017, "Entity": "India", "Value_co2_emissions_kt_by_country": 2320409.912, "Electricity from fossil fuels (TWh)": 1198.85, "Electricity from nuclear (TWh)": 37.41, "Electricity from renewables (TWh)": 234.9}, {"Year": 2018, "Entity": "India", "Value_co2_emissions_kt_by_country": 2451929.932, "Electricity from fossil fuels (TWh)": 1276.32, "Electricity from nuclear (TWh)": 39.05, "Electricity from renewables (TWh)": 263.61}, {"Year": 2019, "Entity": "India", "Value_co2_emissions_kt_by_country": 2456300.049, "Electricity from fossil fuels (TWh)": 1273.59, "Electricity from nuclear (TWh)": 45.16, "Electricity from renewables (TWh)": 303.16}, {"Year": 2020, "Entity": "India", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 1202.34, "Electricity from nuclear (TWh)": 44.61, "Electricity from renewables (TWh)": 315.76}, {"Year": 2000, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 280650, "Electricity from fossil fuels (TWh)": 78.43, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 19.6}, {"Year": 2001, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 302060, "Electricity from fossil fuels (TWh)": 83.96, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 22.19}, {"Year": 2002, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 305640.0146, "Electricity from fossil fuels (TWh)": 92.03, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 21}, {"Year": 2003, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 333890.0146, "Electricity from fossil fuels (TWh)": 97.57, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 19.82}, {"Year": 2004, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 341239.9902, "Electricity from fossil fuels (TWh)": 103.8, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 20.97}, {"Year": 2005, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 342149.9939, "Electricity from fossil fuels (TWh)": 110.22, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 22.66}, {"Year": 2006, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 364470.0012, "Electricity from fossil fuels (TWh)": 116.8, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 21.18}, {"Year": 2007, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 379959.9915, "Electricity from fossil fuels (TWh)": 124.1, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 24.29}, {"Year": 2008, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 376140.0146, "Electricity from fossil fuels (TWh)": 129.55, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 26.34}, {"Year": 2009, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 391079.9866, "Electricity from fossil fuels (TWh)": 136.05, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 26.79}, {"Year": 2010, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 415519.989, "Electricity from fossil fuels (TWh)": 142.88, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 34.63}, {"Year": 2011, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 475309.9976, "Electricity from fossil fuels (TWh)": 161.41, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 30.46}, {"Year": 2012, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 481510.0098, "Electricity from fossil fuels (TWh)": 177.83, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 31.11}, {"Year": 2013, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 447940.0024, "Electricity from fossil fuels (TWh)": 189.66, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 35.5}, {"Year": 2014, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 483910.0037, "Electricity from fossil fuels (TWh)": 203.11, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 34.41}, {"Year": 2015, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 488549.9878, "Electricity from fossil fuels (TWh)": 209.71, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 33.56}, {"Year": 2016, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 482510.0098, "Electricity from fossil fuels (TWh)": 217.97, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 39.58}, {"Year": 2017, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 517320.0073, "Electricity from fossil fuels (TWh)": 222.64, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 43.17}, {"Year": 2018, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 576989.9902, "Electricity from fossil fuels (TWh)": 235.41, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 48.38}, {"Year": 2019, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": 619840.0269, "Electricity from fossil fuels (TWh)": 247.39, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 48.04}, {"Year": 2020, "Entity": "Indonesia", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 238.91, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 52.91}, {"Year": 2000, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 436300, "Electricity from fossil fuels (TWh)": 218.28, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 50.87}, {"Year": 2001, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 436570, "Electricity from fossil fuels (TWh)": 216.73, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 54.35}, {"Year": 2002, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 443470.0012, "Electricity from fossil fuels (TWh)": 228.45, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 48.31}, {"Year": 2003, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 462200.0122, "Electricity from fossil fuels (TWh)": 238.52, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 46.86}, {"Year": 2004, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 472399.9939, "Electricity from fossil fuels (TWh)": 240.95, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 53.88}, {"Year": 2005, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 473829.9866, "Electricity from fossil fuels (TWh)": 247.29, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 48.43}, {"Year": 2006, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 466649.9939, "Electricity from fossil fuels (TWh)": 256.03, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 50.64}, {"Year": 2007, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 459369.9951, "Electricity from fossil fuels (TWh)": 259.49, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 47.72}, {"Year": 2008, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 444980.011, "Electricity from fossil fuels (TWh)": 254.34, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 58.16}, {"Year": 2009, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 397059.9976, "Electricity from fossil fuels (TWh)": 218.32, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 69.26}, {"Year": 2010, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 405269.989, "Electricity from fossil fuels (TWh)": 220.93, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 76.98}, {"Year": 2011, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 396690.0024, "Electricity from fossil fuels (TWh)": 216.78, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 82.96}, {"Year": 2012, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 376750, "Electricity from fossil fuels (TWh)": 204.26, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 92.22}, {"Year": 2013, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 346459.9915, "Electricity from fossil fuels (TWh)": 175.07, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 112}, {"Year": 2014, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 327500, "Electricity from fossil fuels (TWh)": 156.76, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 120.68}, {"Year": 2015, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 337859.9854, "Electricity from fossil fuels (TWh)": 172.06, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 108.89}, {"Year": 2016, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 333339.9963, "Electricity from fossil fuels (TWh)": 179.19, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 108.01}, {"Year": 2017, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 329190.0024, "Electricity from fossil fuels (TWh)": 189.44, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 103.89}, {"Year": 2018, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 324880.0049, "Electricity from fossil fuels (TWh)": 172.98, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 114.41}, {"Year": 2019, "Entity": "Italy", "Value_co2_emissions_kt_by_country": 317239.9902, "Electricity from fossil fuels (TWh)": 175.52, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 115.83}, {"Year": 2020, "Entity": "Italy", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 161.17, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 116.9}, {"Year": 2000, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1182610, "Electricity from fossil fuels (TWh)": 578.29, "Electricity from nuclear (TWh)": 305.95, "Electricity from renewables (TWh)": 104.16}, {"Year": 2001, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1170380, "Electricity from fossil fuels (TWh)": 564.95, "Electricity from nuclear (TWh)": 303.86, "Electricity from renewables (TWh)": 101.36}, {"Year": 2002, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1206599.976, "Electricity from fossil fuels (TWh)": 605.12, "Electricity from nuclear (TWh)": 280.34, "Electricity from renewables (TWh)": 101.1}, {"Year": 2003, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1214949.951, "Electricity from fossil fuels (TWh)": 633.76, "Electricity from nuclear (TWh)": 228.01, "Electricity from renewables (TWh)": 114.18}, {"Year": 2004, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1209849.976, "Electricity from fossil fuels (TWh)": 621.6, "Electricity from nuclear (TWh)": 268.32, "Electricity from renewables (TWh)": 114.73}, {"Year": 2005, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1212819.946, "Electricity from fossil fuels (TWh)": 634.09, "Electricity from nuclear (TWh)": 280.5, "Electricity from renewables (TWh)": 100.57}, {"Year": 2006, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1189520.02, "Electricity from fossil fuels (TWh)": 628.77, "Electricity from nuclear (TWh)": 291.54, "Electricity from renewables (TWh)": 112.07}, {"Year": 2007, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1225069.946, "Electricity from fossil fuels (TWh)": 705.37, "Electricity from nuclear (TWh)": 267.34, "Electricity from renewables (TWh)": 100.8}, {"Year": 2008, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1158219.971, "Electricity from fossil fuels (TWh)": 663.88, "Electricity from nuclear (TWh)": 241.25, "Electricity from renewables (TWh)": 100.79}, {"Year": 2009, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1100979.98, "Electricity from fossil fuels (TWh)": 611.86, "Electricity from nuclear (TWh)": 263.05, "Electricity from renewables (TWh)": 102.28}, {"Year": 2010, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1156479.98, "Electricity from fossil fuels (TWh)": 689.89, "Electricity from nuclear (TWh)": 278.36, "Electricity from renewables (TWh)": 113.92}, {"Year": 2011, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1213520.02, "Electricity from fossil fuels (TWh)": 777.1, "Electricity from nuclear (TWh)": 153.38, "Electricity from renewables (TWh)": 116.5}, {"Year": 2012, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1253609.985, "Electricity from fossil fuels (TWh)": 920.39, "Electricity from nuclear (TWh)": 15.12, "Electricity from renewables (TWh)": 111.09}, {"Year": 2013, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1262780.029, "Electricity from fossil fuels (TWh)": 897.88, "Electricity from nuclear (TWh)": 10.43, "Electricity from renewables (TWh)": 121.48}, {"Year": 2014, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1217119.995, "Electricity from fossil fuels (TWh)": 892.18, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 136.53}, {"Year": 2015, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1179439.941, "Electricity from fossil fuels (TWh)": 844.23, "Electricity from nuclear (TWh)": 3.24, "Electricity from renewables (TWh)": 157.34}, {"Year": 2016, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1167790.039, "Electricity from fossil fuels (TWh)": 832.4, "Electricity from nuclear (TWh)": 14.87, "Electricity from renewables (TWh)": 157.7}, {"Year": 2017, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1155229.98, "Electricity from fossil fuels (TWh)": 806.12, "Electricity from nuclear (TWh)": 27.75, "Electricity from renewables (TWh)": 175.12}, {"Year": 2018, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1116150.024, "Electricity from fossil fuels (TWh)": 780.61, "Electricity from nuclear (TWh)": 47.82, "Electricity from renewables (TWh)": 183.63}, {"Year": 2019, "Entity": "Japan", "Value_co2_emissions_kt_by_country": 1081569.946, "Electricity from fossil fuels (TWh)": 735.66, "Electricity from nuclear (TWh)": 63.88, "Electricity from renewables (TWh)": 192.72}, {"Year": 2020, "Entity": "Japan", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 716.67, "Electricity from nuclear (TWh)": 41.86, "Electricity from renewables (TWh)": 205.6}, {"Year": 2000, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 120150, "Electricity from fossil fuels (TWh)": 44.11, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.53}, {"Year": 2001, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 117440, "Electricity from fossil fuels (TWh)": 47.3, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.08}, {"Year": 2002, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 131059.9976, "Electricity from fossil fuels (TWh)": 49.44, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.89}, {"Year": 2003, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 146139.9994, "Electricity from fossil fuels (TWh)": 55.24, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.62}, {"Year": 2004, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 158029.9988, "Electricity from fossil fuels (TWh)": 58.89, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.06}, {"Year": 2005, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 169210.0067, "Electricity from fossil fuels (TWh)": 60.06, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.86}, {"Year": 2006, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 185300.0031, "Electricity from fossil fuels (TWh)": 63.89, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.77}, {"Year": 2007, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 198389.9994, "Electricity from fossil fuels (TWh)": 68.45, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.17}, {"Year": 2008, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 242029.9988, "Electricity from fossil fuels (TWh)": 72.89, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.46}, {"Year": 2009, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 213610.0006, "Electricity from fossil fuels (TWh)": 71.85, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 6.88}, {"Year": 2010, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 229699.9969, "Electricity from fossil fuels (TWh)": 74.63, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.02}, {"Year": 2011, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 245449.9969, "Electricity from fossil fuels (TWh)": 78.7, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.88}, {"Year": 2012, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 244600.0061, "Electricity from fossil fuels (TWh)": 82.98, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.64}, {"Year": 2013, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 260010.0098, "Electricity from fossil fuels (TWh)": 84.88, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 7.73}, {"Year": 2014, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 209229.9957, "Electricity from fossil fuels (TWh)": 86.37, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 8.27}, {"Year": 2015, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 190729.9957, "Electricity from fossil fuels (TWh)": 82.2, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 9.45}, {"Year": 2016, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 202149.9939, "Electricity from fossil fuels (TWh)": 82.65, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 11.98}, {"Year": 2017, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 214580.0018, "Electricity from fossil fuels (TWh)": 91.48, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 11.64}, {"Year": 2018, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 216600.0061, "Electricity from fossil fuels (TWh)": 96.36, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 10.91}, {"Year": 2019, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": 212110.0006, "Electricity from fossil fuels (TWh)": 95.39, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 11.09}, {"Year": 2020, "Entity": "Kazakhstan", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 96.7, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 11.94}, {"Year": 2000, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 379180, "Electricity from fossil fuels (TWh)": 141.8, "Electricity from nuclear (TWh)": 7.81, "Electricity from renewables (TWh)": 44.51}, {"Year": 2001, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 378830, "Electricity from fossil fuels (TWh)": 153.32, "Electricity from nuclear (TWh)": 8.29, "Electricity from renewables (TWh)": 39.56}, {"Year": 2002, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 386000, "Electricity from fossil fuels (TWh)": 159.81, "Electricity from nuclear (TWh)": 9.26, "Electricity from renewables (TWh)": 35.67}, {"Year": 2003, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 404690.0024, "Electricity from fossil fuels (TWh)": 160.45, "Electricity from nuclear (TWh)": 9.98, "Electricity from renewables (TWh)": 32.11}, {"Year": 2004, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 414100.0061, "Electricity from fossil fuels (TWh)": 173.66, "Electricity from nuclear (TWh)": 8.73, "Electricity from renewables (TWh)": 38.19}, {"Year": 2005, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 432190.0024, "Electricity from fossil fuels (TWh)": 178.76, "Electricity from nuclear (TWh)": 10.32, "Electricity from renewables (TWh)": 42.29}, {"Year": 2006, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 448299.9878, "Electricity from fossil fuels (TWh)": 182.76, "Electricity from nuclear (TWh)": 10.4, "Electricity from renewables (TWh)": 43.63}, {"Year": 2007, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 457119.9951, "Electricity from fossil fuels (TWh)": 191.83, "Electricity from nuclear (TWh)": 9.95, "Electricity from renewables (TWh)": 42.14}, {"Year": 2008, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 459549.9878, "Electricity from fossil fuels (TWh)": 184.51, "Electricity from nuclear (TWh)": 9.36, "Electricity from renewables (TWh)": 53.22}, {"Year": 2009, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 448369.9951, "Electricity from fossil fuels (TWh)": 194.75, "Electricity from nuclear (TWh)": 10.11, "Electricity from renewables (TWh)": 40.59}, {"Year": 2010, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 462869.9951, "Electricity from fossil fuels (TWh)": 207.38, "Electricity from nuclear (TWh)": 5.66, "Electricity from renewables (TWh)": 51.37}, {"Year": 2011, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 478399.9939, "Electricity from fossil fuels (TWh)": 219.88, "Electricity from nuclear (TWh)": 9.66, "Electricity from renewables (TWh)": 50.7}, {"Year": 2012, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 486450.0122, "Electricity from fossil fuels (TWh)": 229.14, "Electricity from nuclear (TWh)": 8.41, "Electricity from renewables (TWh)": 47.2}, {"Year": 2013, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 475739.9902, "Electricity from fossil fuels (TWh)": 231.23, "Electricity from nuclear (TWh)": 11.38, "Electricity from renewables (TWh)": 44.67}, {"Year": 2014, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 462239.9902, "Electricity from fossil fuels (TWh)": 223.43, "Electricity from nuclear (TWh)": 9.3, "Electricity from renewables (TWh)": 57.46}, {"Year": 2015, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 471630.0049, "Electricity from fossil fuels (TWh)": 234.28, "Electricity from nuclear (TWh)": 11.18, "Electricity from renewables (TWh)": 52.42}, {"Year": 2016, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 473309.9976, "Electricity from fossil fuels (TWh)": 239.78, "Electricity from nuclear (TWh)": 10.27, "Electricity from renewables (TWh)": 52.97}, {"Year": 2017, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 471579.9866, "Electricity from fossil fuels (TWh)": 242.69, "Electricity from nuclear (TWh)": 10.57, "Electricity from renewables (TWh)": 55.88}, {"Year": 2018, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 452570.0073, "Electricity from fossil fuels (TWh)": 259.92, "Electricity from nuclear (TWh)": 13.32, "Electricity from renewables (TWh)": 58.78}, {"Year": 2019, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": 449269.989, "Electricity from fossil fuels (TWh)": 248.2, "Electricity from nuclear (TWh)": 10.88, "Electricity from renewables (TWh)": 59}, {"Year": 2020, "Entity": "Mexico", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 245.46, "Electricity from nuclear (TWh)": 10.87, "Electricity from renewables (TWh)": 69.19}, {"Year": 2000, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 295770, "Electricity from fossil fuels (TWh)": 140.85, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 2.33}, {"Year": 2001, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 293630, "Electricity from fossil fuels (TWh)": 140.94, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 2.78}, {"Year": 2002, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 287320.0073, "Electricity from fossil fuels (TWh)": 139.72, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 2.77}, {"Year": 2003, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 297730.011, "Electricity from fossil fuels (TWh)": 147.76, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 2.25}, {"Year": 2004, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 301850.0061, "Electricity from fossil fuels (TWh)": 149.06, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 3.2}, {"Year": 2005, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 301350.0061, "Electricity from fossil fuels (TWh)": 151.2, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 3.85}, {"Year": 2006, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 314089.9963, "Electricity from fossil fuels (TWh)": 156.16, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 4.29}, {"Year": 2007, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 313380.0049, "Electricity from fossil fuels (TWh)": 153.08, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 5.43}, {"Year": 2008, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 308329.9866, "Electricity from fossil fuels (TWh)": 148.03, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 6.61}, {"Year": 2009, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 297260.0098, "Electricity from fossil fuels (TWh)": 142.4, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.69}, {"Year": 2010, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 313739.9902, "Electricity from fossil fuels (TWh)": 146.12, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 10.88}, {"Year": 2011, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 310589.9963, "Electricity from fossil fuels (TWh)": 149.88, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 13.13}, {"Year": 2012, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 303350.0061, "Electricity from fossil fuels (TWh)": 144.75, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 16.88}, {"Year": 2013, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 298299.9878, "Electricity from fossil fuels (TWh)": 146.85, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 17.06}, {"Year": 2014, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 285730.011, "Electricity from fossil fuels (TWh)": 138.53, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 19.85}, {"Year": 2015, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 289079.9866, "Electricity from fossil fuels (TWh)": 141.55, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 22.69}, {"Year": 2016, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 299799.9878, "Electricity from fossil fuels (TWh)": 143.28, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 22.81}, {"Year": 2017, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 312859.9854, "Electricity from fossil fuels (TWh)": 145.8, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 24.13}, {"Year": 2018, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 311910.0037, "Electricity from fossil fuels (TWh)": 147.87, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 21.62}, {"Year": 2019, "Entity": "Poland", "Value_co2_emissions_kt_by_country": 295130.0049, "Electricity from fossil fuels (TWh)": 137.58, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 25.46}, {"Year": 2020, "Entity": "Poland", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 128.91, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 28.23}, {"Year": 2000, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 249660, "Electricity from fossil fuels (TWh)": 138.68, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2001, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 254090, "Electricity from fossil fuels (TWh)": 146.09, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2002, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 272250, "Electricity from fossil fuels (TWh)": 154.91, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2003, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 284829.9866, "Electricity from fossil fuels (TWh)": 166.58, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2004, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 299890.0146, "Electricity from fossil fuels (TWh)": 173.41, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2005, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 315290.0085, "Electricity from fossil fuels (TWh)": 191.05, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2006, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 335440.0024, "Electricity from fossil fuels (TWh)": 196.31, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2007, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 354619.9951, "Electricity from fossil fuels (TWh)": 204.43, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2008, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 389720.0012, "Electricity from fossil fuels (TWh)": 204.2, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2009, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 406529.9988, "Electricity from fossil fuels (TWh)": 217.31, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2010, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 446130.0049, "Electricity from fossil fuels (TWh)": 240.06, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0}, {"Year": 2011, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 463769.989, "Electricity from fossil fuels (TWh)": 250.07, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.01}, {"Year": 2012, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 492470.0012, "Electricity from fossil fuels (TWh)": 271.68, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.03}, {"Year": 2013, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 503209.9915, "Electricity from fossil fuels (TWh)": 284.02, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.04}, {"Year": 2014, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 540520.0195, "Electricity from fossil fuels (TWh)": 311.81, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.05}, {"Year": 2015, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 565190.0024, "Electricity from fossil fuels (TWh)": 338.34, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.05}, {"Year": 2016, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 561229.9805, "Electricity from fossil fuels (TWh)": 337.38, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.05}, {"Year": 2017, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 545070.0073, "Electricity from fossil fuels (TWh)": 354.3, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.07}, {"Year": 2018, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 521260.0098, "Electricity from fossil fuels (TWh)": 334.7, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.16}, {"Year": 2019, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": 523780.0293, "Electricity from fossil fuels (TWh)": 335.24, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.21}, {"Year": 2020, "Entity": "Saudi Arabia", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 337.82, "Electricity from nuclear (TWh)": null, "Electricity from renewables (TWh)": 0.21}, {"Year": 2000, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 284660, "Electricity from fossil fuels (TWh)": 181.67, "Electricity from nuclear (TWh)": 13.01, "Electricity from renewables (TWh)": 1.79}, {"Year": 2001, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 320540, "Electricity from fossil fuels (TWh)": 183.36, "Electricity from nuclear (TWh)": 10.72, "Electricity from renewables (TWh)": 2.46}, {"Year": 2002, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 331320.0073, "Electricity from fossil fuels (TWh)": 188.79, "Electricity from nuclear (TWh)": 11.99, "Electricity from renewables (TWh)": 2.81}, {"Year": 2003, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 353089.9963, "Electricity from fossil fuels (TWh)": 204.39, "Electricity from nuclear (TWh)": 12.66, "Electricity from renewables (TWh)": 1.19}, {"Year": 2004, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 379989.9902, "Electricity from fossil fuels (TWh)": 212.63, "Electricity from nuclear (TWh)": 14.28, "Electricity from renewables (TWh)": 1.33}, {"Year": 2005, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 377649.9939, "Electricity from fossil fuels (TWh)": 215.23, "Electricity from nuclear (TWh)": 12.24, "Electricity from renewables (TWh)": 1.75}, {"Year": 2006, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 379790.0085, "Electricity from fossil fuels (TWh)": 223.25, "Electricity from nuclear (TWh)": 10.07, "Electricity from renewables (TWh)": 3.28}, {"Year": 2007, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 397059.9976, "Electricity from fossil fuels (TWh)": 232.91, "Electricity from nuclear (TWh)": 12.6, "Electricity from renewables (TWh)": 1.3}, {"Year": 2008, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 426739.9902, "Electricity from fossil fuels (TWh)": 226.32, "Electricity from nuclear (TWh)": 12.75, "Electricity from renewables (TWh)": 1.66}, {"Year": 2009, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 404200.0122, "Electricity from fossil fuels (TWh)": 218.17, "Electricity from nuclear (TWh)": 11.57, "Electricity from renewables (TWh)": 1.86}, {"Year": 2010, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 425309.9976, "Electricity from fossil fuels (TWh)": 227.57, "Electricity from nuclear (TWh)": 12.9, "Electricity from renewables (TWh)": 2.51}, {"Year": 2011, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 409260.0098, "Electricity from fossil fuels (TWh)": 229.06, "Electricity from nuclear (TWh)": 12.94, "Electricity from renewables (TWh)": 2.49}, {"Year": 2012, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 426779.9988, "Electricity from fossil fuels (TWh)": 226.84, "Electricity from nuclear (TWh)": 12.4, "Electricity from renewables (TWh)": 1.66}, {"Year": 2013, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 436920.0134, "Electricity from fossil fuels (TWh)": 223.28, "Electricity from nuclear (TWh)": 13.61, "Electricity from renewables (TWh)": 1.62}, {"Year": 2014, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 447929.9927, "Electricity from fossil fuels (TWh)": 218.42, "Electricity from nuclear (TWh)": 14.76, "Electricity from renewables (TWh)": 3.38}, {"Year": 2015, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 424809.9976, "Electricity from fossil fuels (TWh)": 214.88, "Electricity from nuclear (TWh)": 10.97, "Electricity from renewables (TWh)": 6.09}, {"Year": 2016, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 425140.0146, "Electricity from fossil fuels (TWh)": 213.09, "Electricity from nuclear (TWh)": 15.21, "Electricity from renewables (TWh)": 7.69}, {"Year": 2017, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 435649.9939, "Electricity from fossil fuels (TWh)": 212.77, "Electricity from nuclear (TWh)": 15.09, "Electricity from renewables (TWh)": 10.04}, {"Year": 2018, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 434350.0061, "Electricity from fossil fuels (TWh)": 214.25, "Electricity from nuclear (TWh)": 10.56, "Electricity from renewables (TWh)": 12.22}, {"Year": 2019, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": 439640.0146, "Electricity from fossil fuels (TWh)": 208.39, "Electricity from nuclear (TWh)": 13.6, "Electricity from renewables (TWh)": 12.57}, {"Year": 2020, "Entity": "South Africa", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 197.5, "Electricity from nuclear (TWh)": 11.62, "Electricity from renewables (TWh)": 12.83}, {"Year": 2000, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 293310, "Electricity from fossil fuels (TWh)": 124.22, "Electricity from nuclear (TWh)": 62.21, "Electricity from renewables (TWh)": 34.49}, {"Year": 2001, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 294790, "Electricity from fossil fuels (TWh)": 120.06, "Electricity from nuclear (TWh)": 63.71, "Electricity from renewables (TWh)": 49.3}, {"Year": 2002, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 312750, "Electricity from fossil fuels (TWh)": 143.72, "Electricity from nuclear (TWh)": 63.02, "Electricity from renewables (TWh)": 33.17}, {"Year": 2003, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 318660.0037, "Electricity from fossil fuels (TWh)": 139.67, "Electricity from nuclear (TWh)": 61.88, "Electricity from renewables (TWh)": 55.75}, {"Year": 2004, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 335559.9976, "Electricity from fossil fuels (TWh)": 159.91, "Electricity from nuclear (TWh)": 63.61, "Electricity from renewables (TWh)": 50.13}, {"Year": 2005, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 350500, "Electricity from fossil fuels (TWh)": 184.65, "Electricity from nuclear (TWh)": 57.54, "Electricity from renewables (TWh)": 42.27}, {"Year": 2006, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 341779.9988, "Electricity from fossil fuels (TWh)": 182.98, "Electricity from nuclear (TWh)": 60.13, "Electricity from renewables (TWh)": 52.15}, {"Year": 2007, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 354679.9927, "Electricity from fossil fuels (TWh)": 188.13, "Electricity from nuclear (TWh)": 55.1, "Electricity from renewables (TWh)": 58.3}, {"Year": 2008, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 324269.989, "Electricity from fossil fuels (TWh)": 189.55, "Electricity from nuclear (TWh)": 58.97, "Electricity from renewables (TWh)": 62.15}, {"Year": 2009, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 287489.9902, "Electricity from fossil fuels (TWh)": 164.69, "Electricity from nuclear (TWh)": 52.76, "Electricity from renewables (TWh)": 74.08}, {"Year": 2010, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 273250, "Electricity from fossil fuels (TWh)": 138.39, "Electricity from nuclear (TWh)": 61.99, "Electricity from renewables (TWh)": 97.77}, {"Year": 2011, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 274399.9939, "Electricity from fossil fuels (TWh)": 146.12, "Electricity from nuclear (TWh)": 57.72, "Electricity from renewables (TWh)": 87.53}, {"Year": 2012, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 269269.989, "Electricity from fossil fuels (TWh)": 145.33, "Electricity from nuclear (TWh)": 61.47, "Electricity from renewables (TWh)": 86.97}, {"Year": 2013, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 242809.9976, "Electricity from fossil fuels (TWh)": 113.32, "Electricity from nuclear (TWh)": 56.73, "Electricity from renewables (TWh)": 111.42}, {"Year": 2014, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 240960.0067, "Electricity from fossil fuels (TWh)": 107.37, "Electricity from nuclear (TWh)": 57.31, "Electricity from renewables (TWh)": 110.26}, {"Year": 2015, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 256279.9988, "Electricity from fossil fuels (TWh)": 123.19, "Electricity from nuclear (TWh)": 57.2, "Electricity from renewables (TWh)": 97.09}, {"Year": 2016, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 247029.9988, "Electricity from fossil fuels (TWh)": 107.93, "Electricity from nuclear (TWh)": 58.63, "Electricity from renewables (TWh)": 104.63}, {"Year": 2017, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 263450.0122, "Electricity from fossil fuels (TWh)": 126.93, "Electricity from nuclear (TWh)": 58.04, "Electricity from renewables (TWh)": 87.93}, {"Year": 2018, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 257040.0085, "Electricity from fossil fuels (TWh)": 112.23, "Electricity from nuclear (TWh)": 55.77, "Electricity from renewables (TWh)": 103.88}, {"Year": 2019, "Entity": "Spain", "Value_co2_emissions_kt_by_country": 239979.9957, "Electricity from fossil fuels (TWh)": 111.55, "Electricity from nuclear (TWh)": 58.35, "Electricity from renewables (TWh)": 100.99}, {"Year": 2020, "Entity": "Spain", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 87.64, "Electricity from nuclear (TWh)": 58.3, "Electricity from renewables (TWh)": 113.79}, {"Year": 2000, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 164490, "Electricity from fossil fuels (TWh)": 83.15, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 6.38}, {"Year": 2001, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 173160, "Electricity from fossil fuels (TWh)": 88.97, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 6.76}, {"Year": 2002, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 184240.0055, "Electricity from fossil fuels (TWh)": 93.51, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.07}, {"Year": 2003, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 191929.9927, "Electricity from fossil fuels (TWh)": 100.61, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.36}, {"Year": 2004, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 210190.0024, "Electricity from fossil fuels (TWh)": 109.46, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 7.63}, {"Year": 2005, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 217770.0043, "Electricity from fossil fuels (TWh)": 115.58, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 7.42}, {"Year": 2006, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 219880.0049, "Electricity from fossil fuels (TWh)": 119.41, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 9.82}, {"Year": 2007, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 224589.9963, "Electricity from fossil fuels (TWh)": 122.12, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 10.2}, {"Year": 2008, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 227580.0018, "Electricity from fossil fuels (TWh)": 127.43, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.95}, {"Year": 2009, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 220259.9945, "Electricity from fossil fuels (TWh)": 128.09, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 9.09}, {"Year": 2010, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 234380.0049, "Electricity from fossil fuels (TWh)": 141.72, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 8.58}, {"Year": 2011, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 233600.0061, "Electricity from fossil fuels (TWh)": 135.31, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 11.83}, {"Year": 2012, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 250679.9927, "Electricity from fossil fuels (TWh)": 143.73, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 13.42}, {"Year": 2013, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 260700.0122, "Electricity from fossil fuels (TWh)": 148.29, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 12.33}, {"Year": 2014, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 256799.9878, "Electricity from fossil fuels (TWh)": 149.26, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 13.68}, {"Year": 2015, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 264000, "Electricity from fossil fuels (TWh)": 153.4, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 13.33}, {"Year": 2016, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 261600.0061, "Electricity from fossil fuels (TWh)": 161.79, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 15.97}, {"Year": 2017, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 258820.0073, "Electricity from fossil fuels (TWh)": 161.88, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 19.92}, {"Year": 2018, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 257049.9878, "Electricity from fossil fuels (TWh)": 156.26, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 25.84}, {"Year": 2019, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": 267089.9963, "Electricity from fossil fuels (TWh)": 162.59, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 28.02}, {"Year": 2020, "Entity": "Thailand", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 154.52, "Electricity from nuclear (TWh)": 0, "Electricity from renewables (TWh)": 24.73}, {"Year": 2000, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 297380, "Electricity from fossil fuels (TWh)": 82.65, "Electricity from nuclear (TWh)": 77.34, "Electricity from renewables (TWh)": 11.28}, {"Year": 2001, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 300550, "Electricity from fossil fuels (TWh)": 84.59, "Electricity from nuclear (TWh)": 76.17, "Electricity from renewables (TWh)": 12.05}, {"Year": 2002, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 303940.0024, "Electricity from fossil fuels (TWh)": 85.93, "Electricity from nuclear (TWh)": 77.99, "Electricity from renewables (TWh)": 9.65}, {"Year": 2003, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 330230.011, "Electricity from fossil fuels (TWh)": 89.52, "Electricity from nuclear (TWh)": 81.41, "Electricity from renewables (TWh)": 9.27}, {"Year": 2004, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 307140.0146, "Electricity from fossil fuels (TWh)": 83.22, "Electricity from nuclear (TWh)": 87.02, "Electricity from renewables (TWh)": 11.78}, {"Year": 2005, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 295410.0037, "Electricity from fossil fuels (TWh)": 84.75, "Electricity from nuclear (TWh)": 88.76, "Electricity from renewables (TWh)": 12.4}, {"Year": 2006, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 303989.9902, "Electricity from fossil fuels (TWh)": 90.09, "Electricity from nuclear (TWh)": 90.22, "Electricity from renewables (TWh)": 12.92}, {"Year": 2007, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 312140.0146, "Electricity from fossil fuels (TWh)": 93.13, "Electricity from nuclear (TWh)": 92.54, "Electricity from renewables (TWh)": 10.47}, {"Year": 2008, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 301200.0122, "Electricity from fossil fuels (TWh)": 90.92, "Electricity from nuclear (TWh)": 89.84, "Electricity from renewables (TWh)": 11.82}, {"Year": 2009, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 251619.9951, "Electricity from fossil fuels (TWh)": 78.58, "Electricity from nuclear (TWh)": 82.92, "Electricity from renewables (TWh)": 12.12}, {"Year": 2010, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 268920.0134, "Electricity from fossil fuels (TWh)": 86.28, "Electricity from nuclear (TWh)": 89.15, "Electricity from renewables (TWh)": 13.39}, {"Year": 2011, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 283339.9963, "Electricity from fossil fuels (TWh)": 93.5, "Electricity from nuclear (TWh)": 90.25, "Electricity from renewables (TWh)": 11.2}, {"Year": 2012, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 277109.9854, "Electricity from fossil fuels (TWh)": 96.99, "Electricity from nuclear (TWh)": 90.14, "Electricity from renewables (TWh)": 11.23}, {"Year": 2013, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 270269.989, "Electricity from fossil fuels (TWh)": 95.39, "Electricity from nuclear (TWh)": 83.21, "Electricity from renewables (TWh)": 15.11}, {"Year": 2014, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 237729.9957, "Electricity from fossil fuels (TWh)": 83.42, "Electricity from nuclear (TWh)": 88.39, "Electricity from renewables (TWh)": 10.17}, {"Year": 2015, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 191070.0073, "Electricity from fossil fuels (TWh)": 66.91, "Electricity from nuclear (TWh)": 87.63, "Electricity from renewables (TWh)": 7.1}, {"Year": 2016, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 201660.0037, "Electricity from fossil fuels (TWh)": 72.66, "Electricity from nuclear (TWh)": 80.95, "Electricity from renewables (TWh)": 9.25}, {"Year": 2017, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 174940.0024, "Electricity from fossil fuels (TWh)": 57.96, "Electricity from nuclear (TWh)": 85.58, "Electricity from renewables (TWh)": 10.88}, {"Year": 2018, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 185619.9951, "Electricity from fossil fuels (TWh)": 60.81, "Electricity from nuclear (TWh)": 84.4, "Electricity from renewables (TWh)": 13.02}, {"Year": 2019, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": 174729.9957, "Electricity from fossil fuels (TWh)": 57.79, "Electricity from nuclear (TWh)": 83, "Electricity from renewables (TWh)": 11.87}, {"Year": 2020, "Entity": "Ukraine", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 54.5, "Electricity from nuclear (TWh)": 76.2, "Electricity from renewables (TWh)": 17.56}, {"Year": 2000, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 530890, "Electricity from fossil fuels (TWh)": 279.34, "Electricity from nuclear (TWh)": 85.06, "Electricity from renewables (TWh)": 9.98}, {"Year": 2001, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 545260, "Electricity from fossil fuels (TWh)": 282.72, "Electricity from nuclear (TWh)": 90.09, "Electricity from renewables (TWh)": 9.56}, {"Year": 2002, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 530789.978, "Electricity from fossil fuels (TWh)": 285.62, "Electricity from nuclear (TWh)": 87.85, "Electricity from renewables (TWh)": 11.13}, {"Year": 2003, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 543039.978, "Electricity from fossil fuels (TWh)": 296.15, "Electricity from nuclear (TWh)": 88.69, "Electricity from renewables (TWh)": 10.62}, {"Year": 2004, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 543080.0171, "Electricity from fossil fuels (TWh)": 297.15, "Electricity from nuclear (TWh)": 80, "Electricity from renewables (TWh)": 14.14}, {"Year": 2005, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 540919.9829, "Electricity from fossil fuels (TWh)": 296.87, "Electricity from nuclear (TWh)": 81.62, "Electricity from renewables (TWh)": 16.93}, {"Year": 2006, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 542059.9976, "Electricity from fossil fuels (TWh)": 299.88, "Electricity from nuclear (TWh)": 75.45, "Electricity from renewables (TWh)": 18.11}, {"Year": 2007, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 530500, "Electricity from fossil fuels (TWh)": 310.26, "Electricity from nuclear (TWh)": 63.03, "Electricity from renewables (TWh)": 19.69}, {"Year": 2008, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 515340.0269, "Electricity from fossil fuels (TWh)": 310.5, "Electricity from nuclear (TWh)": 52.49, "Electricity from renewables (TWh)": 21.85}, {"Year": 2009, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 466489.9902, "Electricity from fossil fuels (TWh)": 278.73, "Electricity from nuclear (TWh)": 69.1, "Electricity from renewables (TWh)": 25.25}, {"Year": 2010, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 482440.0024, "Electricity from fossil fuels (TWh)": 290.59, "Electricity from nuclear (TWh)": 62.14, "Electricity from renewables (TWh)": 26.18}, {"Year": 2011, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 445589.9963, "Electricity from fossil fuels (TWh)": 260.88, "Electricity from nuclear (TWh)": 68.98, "Electricity from renewables (TWh)": 35.2}, {"Year": 2012, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 467779.9988, "Electricity from fossil fuels (TWh)": 249.25, "Electricity from nuclear (TWh)": 70.4, "Electricity from renewables (TWh)": 41.24}, {"Year": 2013, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 453760.0098, "Electricity from fossil fuels (TWh)": 231.56, "Electricity from nuclear (TWh)": 70.61, "Electricity from renewables (TWh)": 53.21}, {"Year": 2014, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 415600.0061, "Electricity from fossil fuels (TWh)": 206.94, "Electricity from nuclear (TWh)": 63.75, "Electricity from renewables (TWh)": 64.52}, {"Year": 2015, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 401079.9866, "Electricity from fossil fuels (TWh)": 182.43, "Electricity from nuclear (TWh)": 70.34, "Electricity from renewables (TWh)": 82.57}, {"Year": 2016, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 380809.9976, "Electricity from fossil fuels (TWh)": 181.56, "Electricity from nuclear (TWh)": 71.73, "Electricity from renewables (TWh)": 82.99}, {"Year": 2017, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 367000, "Electricity from fossil fuels (TWh)": 165.91, "Electricity from nuclear (TWh)": 70.34, "Electricity from renewables (TWh)": 98.85}, {"Year": 2018, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 360730.011, "Electricity from fossil fuels (TWh)": 155.41, "Electricity from nuclear (TWh)": 65.06, "Electricity from renewables (TWh)": 110.03}, {"Year": 2019, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": 348920.0134, "Electricity from fossil fuels (TWh)": 144.99, "Electricity from nuclear (TWh)": 56.18, "Electricity from renewables (TWh)": 120.48}, {"Year": 2020, "Entity": "United Kingdom", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 124.78, "Electricity from nuclear (TWh)": 50.85, "Electricity from renewables (TWh)": 131.74}, {"Year": 2000, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5775810, "Electricity from fossil fuels (TWh)": 2697.28, "Electricity from nuclear (TWh)": 753.89, "Electricity from renewables (TWh)": 350.93}, {"Year": 2001, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5748260, "Electricity from fossil fuels (TWh)": 2678.68, "Electricity from nuclear (TWh)": 768.83, "Electricity from renewables (TWh)": 280.06}, {"Year": 2002, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5593029.785, "Electricity from fossil fuels (TWh)": 2727.83, "Electricity from nuclear (TWh)": 780.06, "Electricity from renewables (TWh)": 336.34}, {"Year": 2003, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5658990.234, "Electricity from fossil fuels (TWh)": 2756.03, "Electricity from nuclear (TWh)": 763.73, "Electricity from renewables (TWh)": 349.18}, {"Year": 2004, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5738290.039, "Electricity from fossil fuels (TWh)": 2818.28, "Electricity from nuclear (TWh)": 788.53, "Electricity from renewables (TWh)": 345.14}, {"Year": 2005, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5753490.234, "Electricity from fossil fuels (TWh)": 2899.96, "Electricity from nuclear (TWh)": 781.99, "Electricity from renewables (TWh)": 353.04}, {"Year": 2006, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5653080.078, "Electricity from fossil fuels (TWh)": 2878.56, "Electricity from nuclear (TWh)": 787.22, "Electricity from renewables (TWh)": 381.16}, {"Year": 2007, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5736319.824, "Electricity from fossil fuels (TWh)": 2988.24, "Electricity from nuclear (TWh)": 806.42, "Electricity from renewables (TWh)": 347.91}, {"Year": 2008, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5558379.883, "Electricity from fossil fuels (TWh)": 2924.21, "Electricity from nuclear (TWh)": 806.21, "Electricity from renewables (TWh)": 377.11}, {"Year": 2009, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5156430.176, "Electricity from fossil fuels (TWh)": 2725.41, "Electricity from nuclear (TWh)": 798.85, "Electricity from renewables (TWh)": 415.56}, {"Year": 2010, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5392109.863, "Electricity from fossil fuels (TWh)": 2882.49, "Electricity from nuclear (TWh)": 806.97, "Electricity from renewables (TWh)": 424.48}, {"Year": 2011, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5173600.098, "Electricity from fossil fuels (TWh)": 2788.93, "Electricity from nuclear (TWh)": 790.2, "Electricity from renewables (TWh)": 509.74}, {"Year": 2012, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4956060.059, "Electricity from fossil fuels (TWh)": 2779.02, "Electricity from nuclear (TWh)": 769.33, "Electricity from renewables (TWh)": 492.32}, {"Year": 2013, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5092100.098, "Electricity from fossil fuels (TWh)": 2746.21, "Electricity from nuclear (TWh)": 789.02, "Electricity from renewables (TWh)": 520.38}, {"Year": 2014, "Entity": "United States", "Value_co2_emissions_kt_by_country": 5107209.961, "Electricity from fossil fuels (TWh)": 2752.01, "Electricity from nuclear (TWh)": 797.17, "Electricity from renewables (TWh)": 546.83}, {"Year": 2015, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4990709.961, "Electricity from fossil fuels (TWh)": 2730.32, "Electricity from nuclear (TWh)": 797.18, "Electricity from renewables (TWh)": 556.49}, {"Year": 2016, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4894500, "Electricity from fossil fuels (TWh)": 2656.96, "Electricity from nuclear (TWh)": 805.69, "Electricity from renewables (TWh)": 624.91}, {"Year": 2017, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4819370.117, "Electricity from fossil fuels (TWh)": 2540.17, "Electricity from nuclear (TWh)": 804.95, "Electricity from renewables (TWh)": 707.19}, {"Year": 2018, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4975310.059, "Electricity from fossil fuels (TWh)": 2661.3, "Electricity from nuclear (TWh)": 807.08, "Electricity from renewables (TWh)": 733.17}, {"Year": 2019, "Entity": "United States", "Value_co2_emissions_kt_by_country": 4817720.215, "Electricity from fossil fuels (TWh)": 2588.21, "Electricity from nuclear (TWh)": 809.41, "Electricity from renewables (TWh)": 760.76}, {"Year": 2020, "Entity": "United States", "Value_co2_emissions_kt_by_country": null, "Electricity from fossil fuels (TWh)": 2431.9, "Electricity from nuclear (TWh)": 789.88, "Electricity from renewables (TWh)": 821.4}], "anchored": true, "attachedMetadata": ""}, {"kind": "table", "id": "table-82", "displayId": "energy-source", "names": ["Entity", "Year", "energy", "source"], "rows": [{"Entity": "Australia", "Year": 2000, "energy": 181.05, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2001, "energy": 194.33, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2002, "energy": 197.29, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2003, "energy": 195.13, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2004, "energy": 203.66, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2005, "energy": 195.95, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2006, "energy": 198.72, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2007, "energy": 208.59, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2008, "energy": 211.06, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2009, "energy": 216.42, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2010, "energy": 212.5, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2011, "energy": 213.56, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2012, "energy": 206.75, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2013, "energy": 195.78, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2014, "energy": 205.46, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2015, "energy": 197.72, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2016, "energy": 207.66, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2017, "energy": 209.14, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2018, "energy": 207.45, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2019, "energy": 196.45, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2020, "energy": 186.92, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2000, "energy": 28.87, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2001, "energy": 35.19, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2002, "energy": 33.5, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2003, "energy": 31.62, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2004, "energy": 40.14, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2005, "energy": 39.56, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2006, "energy": 39.4, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2007, "energy": 37.64, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2008, "energy": 55.87, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2009, "energy": 36.32, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2010, "energy": 61.02, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2011, "energy": 50.27, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2012, "energy": 77.21, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2013, "energy": 112, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2014, "energy": 136.58, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2015, "energy": 128.85, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2016, "energy": 93.06, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2017, "energy": 101.9, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2018, "energy": 86.69, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2019, "energy": 90.91, "source": "fossil fuels"}, {"Entity": "Brazil", "Year": 2020, "energy": 81.15, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2000, "energy": 155.56, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2001, "energy": 159.93, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2002, "energy": 155.12, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2003, "energy": 157.35, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2004, "energy": 148.86, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2005, "energy": 150.78, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2006, "energy": 139.71, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2007, "energy": 149.36, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2008, "energy": 141.33, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2009, "energy": 129.76, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2010, "energy": 130.08, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2011, "energy": 131.3, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2012, "energy": 124.2, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2013, "energy": 122.87, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2014, "energy": 122.75, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2015, "energy": 125.7, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2016, "energy": 122.35, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2017, "energy": 113.7, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2018, "energy": 112.47, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2019, "energy": 110.65, "source": "fossil fuels"}, {"Entity": "Canada", "Year": 2020, "energy": 102.19, "source": "fossil fuels"}, {"Entity": "China", "Year": 2000, "energy": 1113.3, "source": "fossil fuels"}, {"Entity": "China", "Year": 2001, "energy": 1182.59, "source": "fossil fuels"}, {"Entity": "China", "Year": 2002, "energy": 1337.46, "source": "fossil fuels"}, {"Entity": "China", "Year": 2003, "energy": 1579.96, "source": "fossil fuels"}, {"Entity": "China", "Year": 2004, "energy": 1795.41, "source": "fossil fuels"}, {"Entity": "China", "Year": 2005, "energy": 2042.8, "source": "fossil fuels"}, {"Entity": "China", "Year": 2006, "energy": 2364.16, "source": "fossil fuels"}, {"Entity": "China", "Year": 2007, "energy": 2718.7, "source": "fossil fuels"}, {"Entity": "China", "Year": 2008, "energy": 2762.29, "source": "fossil fuels"}, {"Entity": "China", "Year": 2009, "energy": 2980.2, "source": "fossil fuels"}, {"Entity": "China", "Year": 2010, "energy": 3326.19, "source": "fossil fuels"}, {"Entity": "China", "Year": 2011, "energy": 3811.77, "source": "fossil fuels"}, {"Entity": "China", "Year": 2012, "energy": 3869.38, "source": "fossil fuels"}, {"Entity": "China", "Year": 2013, "energy": 4203.77, "source": "fossil fuels"}, {"Entity": "China", "Year": 2014, "energy": 4345.86, "source": "fossil fuels"}, {"Entity": "China", "Year": 2015, "energy": 4222.76, "source": "fossil fuels"}, {"Entity": "China", "Year": 2016, "energy": 4355, "source": "fossil fuels"}, {"Entity": "China", "Year": 2017, "energy": 4643.1, "source": "fossil fuels"}, {"Entity": "China", "Year": 2018, "energy": 4990.28, "source": "fossil fuels"}, {"Entity": "China", "Year": 2019, "energy": 5098.22, "source": "fossil fuels"}, {"Entity": "China", "Year": 2020, "energy": 5184.13, "source": "fossil fuels"}, {"Entity": "France", "Year": 2000, "energy": 50.61, "source": "fossil fuels"}, {"Entity": "France", "Year": 2001, "energy": 46.48, "source": "fossil fuels"}, {"Entity": "France", "Year": 2002, "energy": 52.67, "source": "fossil fuels"}, {"Entity": "France", "Year": 2003, "energy": 57.38, "source": "fossil fuels"}, {"Entity": "France", "Year": 2004, "energy": 56.53, "source": "fossil fuels"}, {"Entity": "France", "Year": 2005, "energy": 63.35, "source": "fossil fuels"}, {"Entity": "France", "Year": 2006, "energy": 56.9, "source": "fossil fuels"}, {"Entity": "France", "Year": 2007, "energy": 58.18, "source": "fossil fuels"}, {"Entity": "France", "Year": 2008, "energy": 55.57, "source": "fossil fuels"}, {"Entity": "France", "Year": 2009, "energy": 51.32, "source": "fossil fuels"}, {"Entity": "France", "Year": 2010, "energy": 57.63, "source": "fossil fuels"}, {"Entity": "France", "Year": 2011, "energy": 58.99, "source": "fossil fuels"}, {"Entity": "France", "Year": 2012, "energy": 56.42, "source": "fossil fuels"}, {"Entity": "France", "Year": 2013, "energy": 53.35, "source": "fossil fuels"}, {"Entity": "France", "Year": 2014, "energy": 35.68, "source": "fossil fuels"}, {"Entity": "France", "Year": 2015, "energy": 44.65, "source": "fossil fuels"}, {"Entity": "France", "Year": 2016, "energy": 56.45, "source": "fossil fuels"}, {"Entity": "France", "Year": 2017, "energy": 65.09, "source": "fossil fuels"}, {"Entity": "France", "Year": 2018, "energy": 49.27, "source": "fossil fuels"}, {"Entity": "France", "Year": 2019, "energy": 53.5, "source": "fossil fuels"}, {"Entity": "France", "Year": 2020, "energy": 48.14, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2000, "energy": 367.22, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2001, "energy": 372.69, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2002, "energy": 372.64, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2003, "energy": 390.81, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2004, "energy": 385.24, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2005, "energy": 386.96, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2006, "energy": 390.03, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2007, "energy": 402.4, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2008, "energy": 390.43, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2009, "energy": 358.07, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2010, "energy": 378.9, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2011, "energy": 373.16, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2012, "energy": 377.89, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2013, "energy": 381.52, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2014, "energy": 360.28, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2015, "energy": 359.99, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2016, "energy": 368.67, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2017, "energy": 353.37, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2018, "energy": 334.65, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2019, "energy": 284.09, "source": "fossil fuels"}, {"Entity": "Germany", "Year": 2020, "energy": 251.4, "source": "fossil fuels"}, {"Entity": "India", "Year": 2000, "energy": 475.35, "source": "fossil fuels"}, {"Entity": "India", "Year": 2001, "energy": 491.01, "source": "fossil fuels"}, {"Entity": "India", "Year": 2002, "energy": 517.51, "source": "fossil fuels"}, {"Entity": "India", "Year": 2003, "energy": 545.36, "source": "fossil fuels"}, {"Entity": "India", "Year": 2004, "energy": 567.86, "source": "fossil fuels"}, {"Entity": "India", "Year": 2005, "energy": 579.32, "source": "fossil fuels"}, {"Entity": "India", "Year": 2006, "energy": 599.24, "source": "fossil fuels"}, {"Entity": "India", "Year": 2007, "energy": 636.68, "source": "fossil fuels"}, {"Entity": "India", "Year": 2008, "energy": 674.27, "source": "fossil fuels"}, {"Entity": "India", "Year": 2009, "energy": 728.56, "source": "fossil fuels"}, {"Entity": "India", "Year": 2010, "energy": 771.78, "source": "fossil fuels"}, {"Entity": "India", "Year": 2011, "energy": 828.16, "source": "fossil fuels"}, {"Entity": "India", "Year": 2012, "energy": 893.45, "source": "fossil fuels"}, {"Entity": "India", "Year": 2013, "energy": 924.93, "source": "fossil fuels"}, {"Entity": "India", "Year": 2014, "energy": 1025.29, "source": "fossil fuels"}, {"Entity": "India", "Year": 2015, "energy": 1080.44, "source": "fossil fuels"}, {"Entity": "India", "Year": 2016, "energy": 1155.52, "source": "fossil fuels"}, {"Entity": "India", "Year": 2017, "energy": 1198.85, "source": "fossil fuels"}, {"Entity": "India", "Year": 2018, "energy": 1276.32, "source": "fossil fuels"}, {"Entity": "India", "Year": 2019, "energy": 1273.59, "source": "fossil fuels"}, {"Entity": "India", "Year": 2020, "energy": 1202.34, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2000, "energy": 78.43, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2001, "energy": 83.96, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2002, "energy": 92.03, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2003, "energy": 97.57, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2004, "energy": 103.8, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2005, "energy": 110.22, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2006, "energy": 116.8, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2007, "energy": 124.1, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2008, "energy": 129.55, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2009, "energy": 136.05, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2010, "energy": 142.88, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2011, "energy": 161.41, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2012, "energy": 177.83, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2013, "energy": 189.66, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2014, "energy": 203.11, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2015, "energy": 209.71, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2016, "energy": 217.97, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2017, "energy": 222.64, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2018, "energy": 235.41, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2019, "energy": 247.39, "source": "fossil fuels"}, {"Entity": "Indonesia", "Year": 2020, "energy": 238.91, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2000, "energy": 218.28, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2001, "energy": 216.73, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2002, "energy": 228.45, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2003, "energy": 238.52, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2004, "energy": 240.95, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2005, "energy": 247.29, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2006, "energy": 256.03, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2007, "energy": 259.49, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2008, "energy": 254.34, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2009, "energy": 218.32, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2010, "energy": 220.93, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2011, "energy": 216.78, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2012, "energy": 204.26, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2013, "energy": 175.07, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2014, "energy": 156.76, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2015, "energy": 172.06, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2016, "energy": 179.19, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2017, "energy": 189.44, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2018, "energy": 172.98, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2019, "energy": 175.52, "source": "fossil fuels"}, {"Entity": "Italy", "Year": 2020, "energy": 161.17, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2000, "energy": 578.29, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2001, "energy": 564.95, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2002, "energy": 605.12, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2003, "energy": 633.76, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2004, "energy": 621.6, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2005, "energy": 634.09, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2006, "energy": 628.77, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2007, "energy": 705.37, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2008, "energy": 663.88, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2009, "energy": 611.86, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2010, "energy": 689.89, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2011, "energy": 777.1, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2012, "energy": 920.39, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2013, "energy": 897.88, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2014, "energy": 892.18, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2015, "energy": 844.23, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2016, "energy": 832.4, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2017, "energy": 806.12, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2018, "energy": 780.61, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2019, "energy": 735.66, "source": "fossil fuels"}, {"Entity": "Japan", "Year": 2020, "energy": 716.67, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2000, "energy": 44.11, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2001, "energy": 47.3, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2002, "energy": 49.44, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2003, "energy": 55.24, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2004, "energy": 58.89, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2005, "energy": 60.06, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2006, "energy": 63.89, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2007, "energy": 68.45, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2008, "energy": 72.89, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2009, "energy": 71.85, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2010, "energy": 74.63, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2011, "energy": 78.7, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2012, "energy": 82.98, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2013, "energy": 84.88, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2014, "energy": 86.37, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2015, "energy": 82.2, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2016, "energy": 82.65, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2017, "energy": 91.48, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2018, "energy": 96.36, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2019, "energy": 95.39, "source": "fossil fuels"}, {"Entity": "Kazakhstan", "Year": 2020, "energy": 96.7, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2000, "energy": 141.8, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2001, "energy": 153.32, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2002, "energy": 159.81, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2003, "energy": 160.45, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2004, "energy": 173.66, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2005, "energy": 178.76, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2006, "energy": 182.76, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2007, "energy": 191.83, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2008, "energy": 184.51, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2009, "energy": 194.75, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2010, "energy": 207.38, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2011, "energy": 219.88, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2012, "energy": 229.14, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2013, "energy": 231.23, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2014, "energy": 223.43, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2015, "energy": 234.28, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2016, "energy": 239.78, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2017, "energy": 242.69, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2018, "energy": 259.92, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2019, "energy": 248.2, "source": "fossil fuels"}, {"Entity": "Mexico", "Year": 2020, "energy": 245.46, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2000, "energy": 140.85, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2001, "energy": 140.94, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2002, "energy": 139.72, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2003, "energy": 147.76, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2004, "energy": 149.06, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2005, "energy": 151.2, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2006, "energy": 156.16, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2007, "energy": 153.08, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2008, "energy": 148.03, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2009, "energy": 142.4, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2010, "energy": 146.12, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2011, "energy": 149.88, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2012, "energy": 144.75, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2013, "energy": 146.85, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2014, "energy": 138.53, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2015, "energy": 141.55, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2016, "energy": 143.28, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2017, "energy": 145.8, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2018, "energy": 147.87, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2019, "energy": 137.58, "source": "fossil fuels"}, {"Entity": "Poland", "Year": 2020, "energy": 128.91, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2000, "energy": 138.68, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2001, "energy": 146.09, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2002, "energy": 154.91, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2003, "energy": 166.58, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2004, "energy": 173.41, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2005, "energy": 191.05, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2006, "energy": 196.31, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2007, "energy": 204.43, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2008, "energy": 204.2, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2009, "energy": 217.31, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2010, "energy": 240.06, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2011, "energy": 250.07, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2012, "energy": 271.68, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2013, "energy": 284.02, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2014, "energy": 311.81, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2015, "energy": 338.34, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2016, "energy": 337.38, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2017, "energy": 354.3, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2018, "energy": 334.7, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2019, "energy": 335.24, "source": "fossil fuels"}, {"Entity": "Saudi Arabia", "Year": 2020, "energy": 337.82, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2000, "energy": 181.67, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2001, "energy": 183.36, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2002, "energy": 188.79, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2003, "energy": 204.39, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2004, "energy": 212.63, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2005, "energy": 215.23, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2006, "energy": 223.25, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2007, "energy": 232.91, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2008, "energy": 226.32, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2009, "energy": 218.17, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2010, "energy": 227.57, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2011, "energy": 229.06, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2012, "energy": 226.84, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2013, "energy": 223.28, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2014, "energy": 218.42, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2015, "energy": 214.88, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2016, "energy": 213.09, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2017, "energy": 212.77, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2018, "energy": 214.25, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2019, "energy": 208.39, "source": "fossil fuels"}, {"Entity": "South Africa", "Year": 2020, "energy": 197.5, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2000, "energy": 124.22, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2001, "energy": 120.06, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2002, "energy": 143.72, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2003, "energy": 139.67, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2004, "energy": 159.91, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2005, "energy": 184.65, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2006, "energy": 182.98, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2007, "energy": 188.13, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2008, "energy": 189.55, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2009, "energy": 164.69, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2010, "energy": 138.39, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2011, "energy": 146.12, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2012, "energy": 145.33, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2013, "energy": 113.32, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2014, "energy": 107.37, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2015, "energy": 123.19, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2016, "energy": 107.93, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2017, "energy": 126.93, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2018, "energy": 112.23, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2019, "energy": 111.55, "source": "fossil fuels"}, {"Entity": "Spain", "Year": 2020, "energy": 87.64, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2000, "energy": 83.15, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2001, "energy": 88.97, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2002, "energy": 93.51, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2003, "energy": 100.61, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2004, "energy": 109.46, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2005, "energy": 115.58, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2006, "energy": 119.41, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2007, "energy": 122.12, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2008, "energy": 127.43, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2009, "energy": 128.09, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2010, "energy": 141.72, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2011, "energy": 135.31, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2012, "energy": 143.73, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2013, "energy": 148.29, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2014, "energy": 149.26, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2015, "energy": 153.4, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2016, "energy": 161.79, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2017, "energy": 161.88, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2018, "energy": 156.26, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2019, "energy": 162.59, "source": "fossil fuels"}, {"Entity": "Thailand", "Year": 2020, "energy": 154.52, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2000, "energy": 82.65, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2001, "energy": 84.59, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2002, "energy": 85.93, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2003, "energy": 89.52, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2004, "energy": 83.22, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2005, "energy": 84.75, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2006, "energy": 90.09, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2007, "energy": 93.13, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2008, "energy": 90.92, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2009, "energy": 78.58, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2010, "energy": 86.28, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2011, "energy": 93.5, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2012, "energy": 96.99, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2013, "energy": 95.39, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2014, "energy": 83.42, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2015, "energy": 66.91, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2016, "energy": 72.66, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2017, "energy": 57.96, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2018, "energy": 60.81, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2019, "energy": 57.79, "source": "fossil fuels"}, {"Entity": "Ukraine", "Year": 2020, "energy": 54.5, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2000, "energy": 279.34, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2001, "energy": 282.72, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2002, "energy": 285.62, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2003, "energy": 296.15, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2004, "energy": 297.15, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2005, "energy": 296.87, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2006, "energy": 299.88, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2007, "energy": 310.26, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2008, "energy": 310.5, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2009, "energy": 278.73, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2010, "energy": 290.59, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2011, "energy": 260.88, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2012, "energy": 249.25, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2013, "energy": 231.56, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2014, "energy": 206.94, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2015, "energy": 182.43, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2016, "energy": 181.56, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2017, "energy": 165.91, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2018, "energy": 155.41, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2019, "energy": 144.99, "source": "fossil fuels"}, {"Entity": "United Kingdom", "Year": 2020, "energy": 124.78, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2000, "energy": 2697.28, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2001, "energy": 2678.68, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2002, "energy": 2727.83, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2003, "energy": 2756.03, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2004, "energy": 2818.28, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2005, "energy": 2899.96, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2006, "energy": 2878.56, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2007, "energy": 2988.24, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2008, "energy": 2924.21, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2009, "energy": 2725.41, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2010, "energy": 2882.49, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2011, "energy": 2788.93, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2012, "energy": 2779.02, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2013, "energy": 2746.21, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2014, "energy": 2752.01, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2015, "energy": 2730.32, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2016, "energy": 2656.96, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2017, "energy": 2540.17, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2018, "energy": 2661.3, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2019, "energy": 2588.21, "source": "fossil fuels"}, {"Entity": "United States", "Year": 2020, "energy": 2431.9, "source": "fossil fuels"}, {"Entity": "Australia", "Year": 2000, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2001, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2002, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2003, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2004, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2005, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2006, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2007, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2008, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2009, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2010, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2011, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2012, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2013, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2015, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2016, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2017, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2018, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2019, "energy": 0, "source": "nuclear"}, {"Entity": "Australia", "Year": 2020, "energy": 0, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2000, "energy": 4.94, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2001, "energy": 14.27, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2002, "energy": 13.84, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2003, "energy": 13.4, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2004, "energy": 11.6, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2005, "energy": 9.2, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2006, "energy": 12.98, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2007, "energy": 11.65, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2008, "energy": 13.21, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2009, "energy": 12.22, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2010, "energy": 13.77, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2011, "energy": 14.8, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2012, "energy": 15.17, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2013, "energy": 14.65, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2014, "energy": 14.46, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2015, "energy": 13.91, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2016, "energy": 14.97, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2017, "energy": 14.86, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2018, "energy": 14.79, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2019, "energy": 15.16, "source": "nuclear"}, {"Entity": "Brazil", "Year": 2020, "energy": 13.21, "source": "nuclear"}, {"Entity": "Canada", "Year": 2000, "energy": 69.16, "source": "nuclear"}, {"Entity": "Canada", "Year": 2001, "energy": 72.86, "source": "nuclear"}, {"Entity": "Canada", "Year": 2002, "energy": 71.75, "source": "nuclear"}, {"Entity": "Canada", "Year": 2003, "energy": 71.15, "source": "nuclear"}, {"Entity": "Canada", "Year": 2004, "energy": 85.87, "source": "nuclear"}, {"Entity": "Canada", "Year": 2005, "energy": 86.83, "source": "nuclear"}, {"Entity": "Canada", "Year": 2006, "energy": 92.44, "source": "nuclear"}, {"Entity": "Canada", "Year": 2007, "energy": 88.19, "source": "nuclear"}, {"Entity": "Canada", "Year": 2008, "energy": 88.3, "source": "nuclear"}, {"Entity": "Canada", "Year": 2009, "energy": 85.13, "source": "nuclear"}, {"Entity": "Canada", "Year": 2010, "energy": 85.53, "source": "nuclear"}, {"Entity": "Canada", "Year": 2011, "energy": 88.29, "source": "nuclear"}, {"Entity": "Canada", "Year": 2012, "energy": 89.49, "source": "nuclear"}, {"Entity": "Canada", "Year": 2013, "energy": 97.58, "source": "nuclear"}, {"Entity": "Canada", "Year": 2014, "energy": 101.21, "source": "nuclear"}, {"Entity": "Canada", "Year": 2015, "energy": 96.05, "source": "nuclear"}, {"Entity": "Canada", "Year": 2016, "energy": 95.69, "source": "nuclear"}, {"Entity": "Canada", "Year": 2017, "energy": 95.57, "source": "nuclear"}, {"Entity": "Canada", "Year": 2018, "energy": 95.03, "source": "nuclear"}, {"Entity": "Canada", "Year": 2019, "energy": 95.47, "source": "nuclear"}, {"Entity": "Canada", "Year": 2020, "energy": 92.65, "source": "nuclear"}, {"Entity": "China", "Year": 2000, "energy": 16.74, "source": "nuclear"}, {"Entity": "China", "Year": 2001, "energy": 17.47, "source": "nuclear"}, {"Entity": "China", "Year": 2002, "energy": 25.13, "source": "nuclear"}, {"Entity": "China", "Year": 2003, "energy": 43.34, "source": "nuclear"}, {"Entity": "China", "Year": 2004, "energy": 50.47, "source": "nuclear"}, {"Entity": "China", "Year": 2005, "energy": 53.09, "source": "nuclear"}, {"Entity": "China", "Year": 2006, "energy": 54.84, "source": "nuclear"}, {"Entity": "China", "Year": 2007, "energy": 62.13, "source": "nuclear"}, {"Entity": "China", "Year": 2008, "energy": 68.39, "source": "nuclear"}, {"Entity": "China", "Year": 2009, "energy": 70.05, "source": "nuclear"}, {"Entity": "China", "Year": 2010, "energy": 74.74, "source": "nuclear"}, {"Entity": "China", "Year": 2011, "energy": 87.2, "source": "nuclear"}, {"Entity": "China", "Year": 2012, "energy": 98.32, "source": "nuclear"}, {"Entity": "China", "Year": 2013, "energy": 111.5, "source": "nuclear"}, {"Entity": "China", "Year": 2014, "energy": 133.22, "source": "nuclear"}, {"Entity": "China", "Year": 2015, "energy": 171.38, "source": "nuclear"}, {"Entity": "China", "Year": 2016, "energy": 213.18, "source": "nuclear"}, {"Entity": "China", "Year": 2017, "energy": 248.1, "source": "nuclear"}, {"Entity": "China", "Year": 2018, "energy": 295, "source": "nuclear"}, {"Entity": "China", "Year": 2019, "energy": 348.7, "source": "nuclear"}, {"Entity": "China", "Year": 2020, "energy": 366.2, "source": "nuclear"}, {"Entity": "France", "Year": 2000, "energy": 415.16, "source": "nuclear"}, {"Entity": "France", "Year": 2001, "energy": 421.08, "source": "nuclear"}, {"Entity": "France", "Year": 2002, "energy": 436.76, "source": "nuclear"}, {"Entity": "France", "Year": 2003, "energy": 441.07, "source": "nuclear"}, {"Entity": "France", "Year": 2004, "energy": 448.24, "source": "nuclear"}, {"Entity": "France", "Year": 2005, "energy": 451.53, "source": "nuclear"}, {"Entity": "France", "Year": 2006, "energy": 450.19, "source": "nuclear"}, {"Entity": "France", "Year": 2007, "energy": 439.73, "source": "nuclear"}, {"Entity": "France", "Year": 2008, "energy": 439.45, "source": "nuclear"}, {"Entity": "France", "Year": 2009, "energy": 409.74, "source": "nuclear"}, {"Entity": "France", "Year": 2010, "energy": 428.52, "source": "nuclear"}, {"Entity": "France", "Year": 2011, "energy": 442.39, "source": "nuclear"}, {"Entity": "France", "Year": 2012, "energy": 425.41, "source": "nuclear"}, {"Entity": "France", "Year": 2013, "energy": 423.68, "source": "nuclear"}, {"Entity": "France", "Year": 2014, "energy": 436.48, "source": "nuclear"}, {"Entity": "France", "Year": 2015, "energy": 437.43, "source": "nuclear"}, {"Entity": "France", "Year": 2016, "energy": 403.2, "source": "nuclear"}, {"Entity": "France", "Year": 2017, "energy": 398.36, "source": "nuclear"}, {"Entity": "France", "Year": 2018, "energy": 412.94, "source": "nuclear"}, {"Entity": "France", "Year": 2019, "energy": 399.01, "source": "nuclear"}, {"Entity": "France", "Year": 2020, "energy": 353.83, "source": "nuclear"}, {"Entity": "Germany", "Year": 2000, "energy": 169.61, "source": "nuclear"}, {"Entity": "Germany", "Year": 2001, "energy": 171.3, "source": "nuclear"}, {"Entity": "Germany", "Year": 2002, "energy": 164.84, "source": "nuclear"}, {"Entity": "Germany", "Year": 2003, "energy": 165.06, "source": "nuclear"}, {"Entity": "Germany", "Year": 2004, "energy": 167.07, "source": "nuclear"}, {"Entity": "Germany", "Year": 2005, "energy": 163.05, "source": "nuclear"}, {"Entity": "Germany", "Year": 2006, "energy": 167.27, "source": "nuclear"}, {"Entity": "Germany", "Year": 2007, "energy": 140.53, "source": "nuclear"}, {"Entity": "Germany", "Year": 2008, "energy": 148.49, "source": "nuclear"}, {"Entity": "Germany", "Year": 2009, "energy": 134.93, "source": "nuclear"}, {"Entity": "Germany", "Year": 2010, "energy": 140.56, "source": "nuclear"}, {"Entity": "Germany", "Year": 2011, "energy": 107.97, "source": "nuclear"}, {"Entity": "Germany", "Year": 2012, "energy": 99.46, "source": "nuclear"}, {"Entity": "Germany", "Year": 2013, "energy": 97.29, "source": "nuclear"}, {"Entity": "Germany", "Year": 2014, "energy": 97.13, "source": "nuclear"}, {"Entity": "Germany", "Year": 2015, "energy": 91.79, "source": "nuclear"}, {"Entity": "Germany", "Year": 2016, "energy": 84.63, "source": "nuclear"}, {"Entity": "Germany", "Year": 2017, "energy": 76.32, "source": "nuclear"}, {"Entity": "Germany", "Year": 2018, "energy": 76, "source": "nuclear"}, {"Entity": "Germany", "Year": 2019, "energy": 75.07, "source": "nuclear"}, {"Entity": "Germany", "Year": 2020, "energy": 64.38, "source": "nuclear"}, {"Entity": "India", "Year": 2000, "energy": 15.77, "source": "nuclear"}, {"Entity": "India", "Year": 2001, "energy": 18.89, "source": "nuclear"}, {"Entity": "India", "Year": 2002, "energy": 19.35, "source": "nuclear"}, {"Entity": "India", "Year": 2003, "energy": 18.14, "source": "nuclear"}, {"Entity": "India", "Year": 2004, "energy": 21.26, "source": "nuclear"}, {"Entity": "India", "Year": 2005, "energy": 17.73, "source": "nuclear"}, {"Entity": "India", "Year": 2006, "energy": 17.63, "source": "nuclear"}, {"Entity": "India", "Year": 2007, "energy": 17.83, "source": "nuclear"}, {"Entity": "India", "Year": 2008, "energy": 15.23, "source": "nuclear"}, {"Entity": "India", "Year": 2009, "energy": 16.82, "source": "nuclear"}, {"Entity": "India", "Year": 2010, "energy": 23.08, "source": "nuclear"}, {"Entity": "India", "Year": 2011, "energy": 32.22, "source": "nuclear"}, {"Entity": "India", "Year": 2012, "energy": 33.14, "source": "nuclear"}, {"Entity": "India", "Year": 2013, "energy": 33.31, "source": "nuclear"}, {"Entity": "India", "Year": 2014, "energy": 34.69, "source": "nuclear"}, {"Entity": "India", "Year": 2015, "energy": 38.31, "source": "nuclear"}, {"Entity": "India", "Year": 2016, "energy": 37.9, "source": "nuclear"}, {"Entity": "India", "Year": 2017, "energy": 37.41, "source": "nuclear"}, {"Entity": "India", "Year": 2018, "energy": 39.05, "source": "nuclear"}, {"Entity": "India", "Year": 2019, "energy": 45.16, "source": "nuclear"}, {"Entity": "India", "Year": 2020, "energy": 44.61, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2000, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2001, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2002, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2003, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2004, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2005, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2006, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2007, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2008, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2009, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2010, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2011, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2012, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2013, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2014, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2015, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2016, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2017, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2018, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2019, "energy": null, "source": "nuclear"}, {"Entity": "Indonesia", "Year": 2020, "energy": null, "source": "nuclear"}, {"Entity": "Italy", "Year": 2000, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2001, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2002, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2003, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2004, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2005, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2006, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2007, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2008, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2009, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2010, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2011, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2012, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2013, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2015, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2016, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2017, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2018, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2019, "energy": 0, "source": "nuclear"}, {"Entity": "Italy", "Year": 2020, "energy": 0, "source": "nuclear"}, {"Entity": "Japan", "Year": 2000, "energy": 305.95, "source": "nuclear"}, {"Entity": "Japan", "Year": 2001, "energy": 303.86, "source": "nuclear"}, {"Entity": "Japan", "Year": 2002, "energy": 280.34, "source": "nuclear"}, {"Entity": "Japan", "Year": 2003, "energy": 228.01, "source": "nuclear"}, {"Entity": "Japan", "Year": 2004, "energy": 268.32, "source": "nuclear"}, {"Entity": "Japan", "Year": 2005, "energy": 280.5, "source": "nuclear"}, {"Entity": "Japan", "Year": 2006, "energy": 291.54, "source": "nuclear"}, {"Entity": "Japan", "Year": 2007, "energy": 267.34, "source": "nuclear"}, {"Entity": "Japan", "Year": 2008, "energy": 241.25, "source": "nuclear"}, {"Entity": "Japan", "Year": 2009, "energy": 263.05, "source": "nuclear"}, {"Entity": "Japan", "Year": 2010, "energy": 278.36, "source": "nuclear"}, {"Entity": "Japan", "Year": 2011, "energy": 153.38, "source": "nuclear"}, {"Entity": "Japan", "Year": 2012, "energy": 15.12, "source": "nuclear"}, {"Entity": "Japan", "Year": 2013, "energy": 10.43, "source": "nuclear"}, {"Entity": "Japan", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Japan", "Year": 2015, "energy": 3.24, "source": "nuclear"}, {"Entity": "Japan", "Year": 2016, "energy": 14.87, "source": "nuclear"}, {"Entity": "Japan", "Year": 2017, "energy": 27.75, "source": "nuclear"}, {"Entity": "Japan", "Year": 2018, "energy": 47.82, "source": "nuclear"}, {"Entity": "Japan", "Year": 2019, "energy": 63.88, "source": "nuclear"}, {"Entity": "Japan", "Year": 2020, "energy": 41.86, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2000, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2001, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2002, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2003, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2004, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2005, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2006, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2007, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2008, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2009, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2010, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2011, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2012, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2013, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2014, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2015, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2016, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2017, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2018, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2019, "energy": null, "source": "nuclear"}, {"Entity": "Kazakhstan", "Year": 2020, "energy": null, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2000, "energy": 7.81, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2001, "energy": 8.29, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2002, "energy": 9.26, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2003, "energy": 9.98, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2004, "energy": 8.73, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2005, "energy": 10.32, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2006, "energy": 10.4, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2007, "energy": 9.95, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2008, "energy": 9.36, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2009, "energy": 10.11, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2010, "energy": 5.66, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2011, "energy": 9.66, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2012, "energy": 8.41, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2013, "energy": 11.38, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2014, "energy": 9.3, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2015, "energy": 11.18, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2016, "energy": 10.27, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2017, "energy": 10.57, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2018, "energy": 13.32, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2019, "energy": 10.88, "source": "nuclear"}, {"Entity": "Mexico", "Year": 2020, "energy": 10.87, "source": "nuclear"}, {"Entity": "Poland", "Year": 2000, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2001, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2002, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2003, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2004, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2005, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2006, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2007, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2008, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2009, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2010, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2011, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2012, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2013, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2015, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2016, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2017, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2018, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2019, "energy": 0, "source": "nuclear"}, {"Entity": "Poland", "Year": 2020, "energy": 0, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2000, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2001, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2002, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2003, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2004, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2005, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2006, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2007, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2008, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2009, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2010, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2011, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2012, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2013, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2014, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2015, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2016, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2017, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2018, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2019, "energy": null, "source": "nuclear"}, {"Entity": "Saudi Arabia", "Year": 2020, "energy": null, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2000, "energy": 13.01, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2001, "energy": 10.72, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2002, "energy": 11.99, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2003, "energy": 12.66, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2004, "energy": 14.28, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2005, "energy": 12.24, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2006, "energy": 10.07, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2007, "energy": 12.6, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2008, "energy": 12.75, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2009, "energy": 11.57, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2010, "energy": 12.9, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2011, "energy": 12.94, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2012, "energy": 12.4, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2013, "energy": 13.61, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2014, "energy": 14.76, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2015, "energy": 10.97, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2016, "energy": 15.21, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2017, "energy": 15.09, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2018, "energy": 10.56, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2019, "energy": 13.6, "source": "nuclear"}, {"Entity": "South Africa", "Year": 2020, "energy": 11.62, "source": "nuclear"}, {"Entity": "Spain", "Year": 2000, "energy": 62.21, "source": "nuclear"}, {"Entity": "Spain", "Year": 2001, "energy": 63.71, "source": "nuclear"}, {"Entity": "Spain", "Year": 2002, "energy": 63.02, "source": "nuclear"}, {"Entity": "Spain", "Year": 2003, "energy": 61.88, "source": "nuclear"}, {"Entity": "Spain", "Year": 2004, "energy": 63.61, "source": "nuclear"}, {"Entity": "Spain", "Year": 2005, "energy": 57.54, "source": "nuclear"}, {"Entity": "Spain", "Year": 2006, "energy": 60.13, "source": "nuclear"}, {"Entity": "Spain", "Year": 2007, "energy": 55.1, "source": "nuclear"}, {"Entity": "Spain", "Year": 2008, "energy": 58.97, "source": "nuclear"}, {"Entity": "Spain", "Year": 2009, "energy": 52.76, "source": "nuclear"}, {"Entity": "Spain", "Year": 2010, "energy": 61.99, "source": "nuclear"}, {"Entity": "Spain", "Year": 2011, "energy": 57.72, "source": "nuclear"}, {"Entity": "Spain", "Year": 2012, "energy": 61.47, "source": "nuclear"}, {"Entity": "Spain", "Year": 2013, "energy": 56.73, "source": "nuclear"}, {"Entity": "Spain", "Year": 2014, "energy": 57.31, "source": "nuclear"}, {"Entity": "Spain", "Year": 2015, "energy": 57.2, "source": "nuclear"}, {"Entity": "Spain", "Year": 2016, "energy": 58.63, "source": "nuclear"}, {"Entity": "Spain", "Year": 2017, "energy": 58.04, "source": "nuclear"}, {"Entity": "Spain", "Year": 2018, "energy": 55.77, "source": "nuclear"}, {"Entity": "Spain", "Year": 2019, "energy": 58.35, "source": "nuclear"}, {"Entity": "Spain", "Year": 2020, "energy": 58.3, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2000, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2001, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2002, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2003, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2004, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2005, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2006, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2007, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2008, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2009, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2010, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2011, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2012, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2013, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2014, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2015, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2016, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2017, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2018, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2019, "energy": 0, "source": "nuclear"}, {"Entity": "Thailand", "Year": 2020, "energy": 0, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2000, "energy": 77.34, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2001, "energy": 76.17, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2002, "energy": 77.99, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2003, "energy": 81.41, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2004, "energy": 87.02, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2005, "energy": 88.76, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2006, "energy": 90.22, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2007, "energy": 92.54, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2008, "energy": 89.84, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2009, "energy": 82.92, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2010, "energy": 89.15, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2011, "energy": 90.25, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2012, "energy": 90.14, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2013, "energy": 83.21, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2014, "energy": 88.39, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2015, "energy": 87.63, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2016, "energy": 80.95, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2017, "energy": 85.58, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2018, "energy": 84.4, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2019, "energy": 83, "source": "nuclear"}, {"Entity": "Ukraine", "Year": 2020, "energy": 76.2, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2000, "energy": 85.06, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2001, "energy": 90.09, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2002, "energy": 87.85, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2003, "energy": 88.69, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2004, "energy": 80, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2005, "energy": 81.62, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2006, "energy": 75.45, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2007, "energy": 63.03, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2008, "energy": 52.49, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2009, "energy": 69.1, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2010, "energy": 62.14, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2011, "energy": 68.98, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2012, "energy": 70.4, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2013, "energy": 70.61, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2014, "energy": 63.75, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2015, "energy": 70.34, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2016, "energy": 71.73, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2017, "energy": 70.34, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2018, "energy": 65.06, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2019, "energy": 56.18, "source": "nuclear"}, {"Entity": "United Kingdom", "Year": 2020, "energy": 50.85, "source": "nuclear"}, {"Entity": "United States", "Year": 2000, "energy": 753.89, "source": "nuclear"}, {"Entity": "United States", "Year": 2001, "energy": 768.83, "source": "nuclear"}, {"Entity": "United States", "Year": 2002, "energy": 780.06, "source": "nuclear"}, {"Entity": "United States", "Year": 2003, "energy": 763.73, "source": "nuclear"}, {"Entity": "United States", "Year": 2004, "energy": 788.53, "source": "nuclear"}, {"Entity": "United States", "Year": 2005, "energy": 781.99, "source": "nuclear"}, {"Entity": "United States", "Year": 2006, "energy": 787.22, "source": "nuclear"}, {"Entity": "United States", "Year": 2007, "energy": 806.42, "source": "nuclear"}, {"Entity": "United States", "Year": 2008, "energy": 806.21, "source": "nuclear"}, {"Entity": "United States", "Year": 2009, "energy": 798.85, "source": "nuclear"}, {"Entity": "United States", "Year": 2010, "energy": 806.97, "source": "nuclear"}, {"Entity": "United States", "Year": 2011, "energy": 790.2, "source": "nuclear"}, {"Entity": "United States", "Year": 2012, "energy": 769.33, "source": "nuclear"}, {"Entity": "United States", "Year": 2013, "energy": 789.02, "source": "nuclear"}, {"Entity": "United States", "Year": 2014, "energy": 797.17, "source": "nuclear"}, {"Entity": "United States", "Year": 2015, "energy": 797.18, "source": "nuclear"}, {"Entity": "United States", "Year": 2016, "energy": 805.69, "source": "nuclear"}, {"Entity": "United States", "Year": 2017, "energy": 804.95, "source": "nuclear"}, {"Entity": "United States", "Year": 2018, "energy": 807.08, "source": "nuclear"}, {"Entity": "United States", "Year": 2019, "energy": 809.41, "source": "nuclear"}, {"Entity": "United States", "Year": 2020, "energy": 789.88, "source": "nuclear"}, {"Entity": "Australia", "Year": 2000, "energy": 17.11, "source": "renewables"}, {"Entity": "Australia", "Year": 2001, "energy": 17.4, "source": "renewables"}, {"Entity": "Australia", "Year": 2002, "energy": 17.35, "source": "renewables"}, {"Entity": "Australia", "Year": 2003, "energy": 18.5, "source": "renewables"}, {"Entity": "Australia", "Year": 2004, "energy": 19.41, "source": "renewables"}, {"Entity": "Australia", "Year": 2005, "energy": 19.75, "source": "renewables"}, {"Entity": "Australia", "Year": 2006, "energy": 21.19, "source": "renewables"}, {"Entity": "Australia", "Year": 2007, "energy": 20.93, "source": "renewables"}, {"Entity": "Australia", "Year": 2008, "energy": 18.49, "source": "renewables"}, {"Entity": "Australia", "Year": 2009, "energy": 18.32, "source": "renewables"}, {"Entity": "Australia", "Year": 2010, "energy": 21.13, "source": "renewables"}, {"Entity": "Australia", "Year": 2011, "energy": 27.33, "source": "renewables"}, {"Entity": "Australia", "Year": 2012, "energy": 26.63, "source": "renewables"}, {"Entity": "Australia", "Year": 2013, "energy": 34.2, "source": "renewables"}, {"Entity": "Australia", "Year": 2014, "energy": 36.15, "source": "renewables"}, {"Entity": "Australia", "Year": 2015, "energy": 33.12, "source": "renewables"}, {"Entity": "Australia", "Year": 2016, "energy": 38.41, "source": "renewables"}, {"Entity": "Australia", "Year": 2017, "energy": 40.77, "source": "renewables"}, {"Entity": "Australia", "Year": 2018, "energy": 42.93, "source": "renewables"}, {"Entity": "Australia", "Year": 2019, "energy": 53.41, "source": "renewables"}, {"Entity": "Australia", "Year": 2020, "energy": 63.99, "source": "renewables"}, {"Entity": "Brazil", "Year": 2000, "energy": 308.77, "source": "renewables"}, {"Entity": "Brazil", "Year": 2001, "energy": 273.71, "source": "renewables"}, {"Entity": "Brazil", "Year": 2002, "energy": 292.95, "source": "renewables"}, {"Entity": "Brazil", "Year": 2003, "energy": 313.88, "source": "renewables"}, {"Entity": "Brazil", "Year": 2004, "energy": 329.43, "source": "renewables"}, {"Entity": "Brazil", "Year": 2005, "energy": 346.96, "source": "renewables"}, {"Entity": "Brazil", "Year": 2006, "energy": 359.55, "source": "renewables"}, {"Entity": "Brazil", "Year": 2007, "energy": 387.88, "source": "renewables"}, {"Entity": "Brazil", "Year": 2008, "energy": 385.61, "source": "renewables"}, {"Entity": "Brazil", "Year": 2009, "energy": 410.13, "source": "renewables"}, {"Entity": "Brazil", "Year": 2010, "energy": 435.99, "source": "renewables"}, {"Entity": "Brazil", "Year": 2011, "energy": 462.32, "source": "renewables"}, {"Entity": "Brazil", "Year": 2012, "energy": 454.78, "source": "renewables"}, {"Entity": "Brazil", "Year": 2013, "energy": 436.84, "source": "renewables"}, {"Entity": "Brazil", "Year": 2014, "energy": 430.82, "source": "renewables"}, {"Entity": "Brazil", "Year": 2015, "energy": 428.81, "source": "renewables"}, {"Entity": "Brazil", "Year": 2016, "energy": 463.37, "source": "renewables"}, {"Entity": "Brazil", "Year": 2017, "energy": 464.4, "source": "renewables"}, {"Entity": "Brazil", "Year": 2018, "energy": 492.66, "source": "renewables"}, {"Entity": "Brazil", "Year": 2019, "energy": 512.59, "source": "renewables"}, {"Entity": "Brazil", "Year": 2020, "energy": 520.01, "source": "renewables"}, {"Entity": "Canada", "Year": 2000, "energy": 363.7, "source": "renewables"}, {"Entity": "Canada", "Year": 2001, "energy": 339.58, "source": "renewables"}, {"Entity": "Canada", "Year": 2002, "energy": 357.06, "source": "renewables"}, {"Entity": "Canada", "Year": 2003, "energy": 343.88, "source": "renewables"}, {"Entity": "Canada", "Year": 2004, "energy": 347.68, "source": "renewables"}, {"Entity": "Canada", "Year": 2005, "energy": 368.86, "source": "renewables"}, {"Entity": "Canada", "Year": 2006, "energy": 360.48, "source": "renewables"}, {"Entity": "Canada", "Year": 2007, "energy": 375.42, "source": "renewables"}, {"Entity": "Canada", "Year": 2008, "energy": 385.21, "source": "renewables"}, {"Entity": "Canada", "Year": 2009, "energy": 380.24, "source": "renewables"}, {"Entity": "Canada", "Year": 2010, "energy": 366.21, "source": "renewables"}, {"Entity": "Canada", "Year": 2011, "energy": 391.95, "source": "renewables"}, {"Entity": "Canada", "Year": 2012, "energy": 398.58, "source": "renewables"}, {"Entity": "Canada", "Year": 2013, "energy": 417.28, "source": "renewables"}, {"Entity": "Canada", "Year": 2014, "energy": 412.13, "source": "renewables"}, {"Entity": "Canada", "Year": 2015, "energy": 417.2, "source": "renewables"}, {"Entity": "Canada", "Year": 2016, "energy": 426.84, "source": "renewables"}, {"Entity": "Canada", "Year": 2017, "energy": 435.43, "source": "renewables"}, {"Entity": "Canada", "Year": 2018, "energy": 428.39, "source": "renewables"}, {"Entity": "Canada", "Year": 2019, "energy": 421.8, "source": "renewables"}, {"Entity": "Canada", "Year": 2020, "energy": 429.24, "source": "renewables"}, {"Entity": "China", "Year": 2000, "energy": 225.56, "source": "renewables"}, {"Entity": "China", "Year": 2001, "energy": 280.73, "source": "renewables"}, {"Entity": "China", "Year": 2002, "energy": 291.41, "source": "renewables"}, {"Entity": "China", "Year": 2003, "energy": 287.28, "source": "renewables"}, {"Entity": "China", "Year": 2004, "energy": 357.43, "source": "renewables"}, {"Entity": "China", "Year": 2005, "energy": 404.37, "source": "renewables"}, {"Entity": "China", "Year": 2006, "energy": 446.72, "source": "renewables"}, {"Entity": "China", "Year": 2007, "energy": 500.71, "source": "renewables"}, {"Entity": "China", "Year": 2008, "energy": 665.08, "source": "renewables"}, {"Entity": "China", "Year": 2009, "energy": 664.39, "source": "renewables"}, {"Entity": "China", "Year": 2010, "energy": 786.38, "source": "renewables"}, {"Entity": "China", "Year": 2011, "energy": 792.38, "source": "renewables"}, {"Entity": "China", "Year": 2012, "energy": 999.56, "source": "renewables"}, {"Entity": "China", "Year": 2013, "energy": 1093.37, "source": "renewables"}, {"Entity": "China", "Year": 2014, "energy": 1289.23, "source": "renewables"}, {"Entity": "China", "Year": 2015, "energy": 1393.66, "source": "renewables"}, {"Entity": "China", "Year": 2016, "energy": 1522.79, "source": "renewables"}, {"Entity": "China", "Year": 2017, "energy": 1667.06, "source": "renewables"}, {"Entity": "China", "Year": 2018, "energy": 1835.32, "source": "renewables"}, {"Entity": "China", "Year": 2019, "energy": 2014.57, "source": "renewables"}, {"Entity": "China", "Year": 2020, "energy": 2184.94, "source": "renewables"}, {"Entity": "France", "Year": 2000, "energy": 67.83, "source": "renewables"}, {"Entity": "France", "Year": 2001, "energy": 76.09, "source": "renewables"}, {"Entity": "France", "Year": 2002, "energy": 62.69, "source": "renewables"}, {"Entity": "France", "Year": 2003, "energy": 61.47, "source": "renewables"}, {"Entity": "France", "Year": 2004, "energy": 62.42, "source": "renewables"}, {"Entity": "France", "Year": 2005, "energy": 54.98, "source": "renewables"}, {"Entity": "France", "Year": 2006, "energy": 60.91, "source": "renewables"}, {"Entity": "France", "Year": 2007, "energy": 64.3, "source": "renewables"}, {"Entity": "France", "Year": 2008, "energy": 72.33, "source": "renewables"}, {"Entity": "France", "Year": 2009, "energy": 68.15, "source": "renewables"}, {"Entity": "France", "Year": 2010, "energy": 76.68, "source": "renewables"}, {"Entity": "France", "Year": 2011, "energy": 66.02, "source": "renewables"}, {"Entity": "France", "Year": 2012, "energy": 85.25, "source": "renewables"}, {"Entity": "France", "Year": 2013, "energy": 99.42, "source": "renewables"}, {"Entity": "France", "Year": 2014, "energy": 94.03, "source": "renewables"}, {"Entity": "France", "Year": 2015, "energy": 91.84, "source": "renewables"}, {"Entity": "France", "Year": 2016, "energy": 99, "source": "renewables"}, {"Entity": "France", "Year": 2017, "energy": 92.63, "source": "renewables"}, {"Entity": "France", "Year": 2018, "energy": 113.62, "source": "renewables"}, {"Entity": "France", "Year": 2019, "energy": 113.21, "source": "renewables"}, {"Entity": "France", "Year": 2020, "energy": 125.28, "source": "renewables"}, {"Entity": "Germany", "Year": 2000, "energy": 35.47, "source": "renewables"}, {"Entity": "Germany", "Year": 2001, "energy": 37.9, "source": "renewables"}, {"Entity": "Germany", "Year": 2002, "energy": 44.48, "source": "renewables"}, {"Entity": "Germany", "Year": 2003, "energy": 46.67, "source": "renewables"}, {"Entity": "Germany", "Year": 2004, "energy": 57.97, "source": "renewables"}, {"Entity": "Germany", "Year": 2005, "energy": 63.4, "source": "renewables"}, {"Entity": "Germany", "Year": 2006, "energy": 72.51, "source": "renewables"}, {"Entity": "Germany", "Year": 2007, "energy": 89.38, "source": "renewables"}, {"Entity": "Germany", "Year": 2008, "energy": 94.28, "source": "renewables"}, {"Entity": "Germany", "Year": 2009, "energy": 95.94, "source": "renewables"}, {"Entity": "Germany", "Year": 2010, "energy": 105.18, "source": "renewables"}, {"Entity": "Germany", "Year": 2011, "energy": 124.04, "source": "renewables"}, {"Entity": "Germany", "Year": 2012, "energy": 143.04, "source": "renewables"}, {"Entity": "Germany", "Year": 2013, "energy": 152.34, "source": "renewables"}, {"Entity": "Germany", "Year": 2014, "energy": 162.54, "source": "renewables"}, {"Entity": "Germany", "Year": 2015, "energy": 188.79, "source": "renewables"}, {"Entity": "Germany", "Year": 2016, "energy": 189.67, "source": "renewables"}, {"Entity": "Germany", "Year": 2017, "energy": 216.32, "source": "renewables"}, {"Entity": "Germany", "Year": 2018, "energy": 222.07, "source": "renewables"}, {"Entity": "Germany", "Year": 2019, "energy": 240.33, "source": "renewables"}, {"Entity": "Germany", "Year": 2020, "energy": 251.48, "source": "renewables"}, {"Entity": "India", "Year": 2000, "energy": 80.27, "source": "renewables"}, {"Entity": "India", "Year": 2001, "energy": 76.19, "source": "renewables"}, {"Entity": "India", "Year": 2002, "energy": 72.78, "source": "renewables"}, {"Entity": "India", "Year": 2003, "energy": 74.63, "source": "renewables"}, {"Entity": "India", "Year": 2004, "energy": 109.2, "source": "renewables"}, {"Entity": "India", "Year": 2005, "energy": 107.47, "source": "renewables"}, {"Entity": "India", "Year": 2006, "energy": 127.56, "source": "renewables"}, {"Entity": "India", "Year": 2007, "energy": 141.75, "source": "renewables"}, {"Entity": "India", "Year": 2008, "energy": 138.91, "source": "renewables"}, {"Entity": "India", "Year": 2009, "energy": 134.33, "source": "renewables"}, {"Entity": "India", "Year": 2010, "energy": 142.61, "source": "renewables"}, {"Entity": "India", "Year": 2011, "energy": 173.62, "source": "renewables"}, {"Entity": "India", "Year": 2012, "energy": 165.25, "source": "renewables"}, {"Entity": "India", "Year": 2013, "energy": 187.9, "source": "renewables"}, {"Entity": "India", "Year": 2014, "energy": 202.04, "source": "renewables"}, {"Entity": "India", "Year": 2015, "energy": 203.21, "source": "renewables"}, {"Entity": "India", "Year": 2016, "energy": 208.21, "source": "renewables"}, {"Entity": "India", "Year": 2017, "energy": 234.9, "source": "renewables"}, {"Entity": "India", "Year": 2018, "energy": 263.61, "source": "renewables"}, {"Entity": "India", "Year": 2019, "energy": 303.16, "source": "renewables"}, {"Entity": "India", "Year": 2020, "energy": 315.76, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2000, "energy": 19.6, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2001, "energy": 22.19, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2002, "energy": 21, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2003, "energy": 19.82, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2004, "energy": 20.97, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2005, "energy": 22.66, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2006, "energy": 21.18, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2007, "energy": 24.29, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2008, "energy": 26.34, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2009, "energy": 26.79, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2010, "energy": 34.63, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2011, "energy": 30.46, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2012, "energy": 31.11, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2013, "energy": 35.5, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2014, "energy": 34.41, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2015, "energy": 33.56, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2016, "energy": 39.58, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2017, "energy": 43.17, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2018, "energy": 48.38, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2019, "energy": 48.04, "source": "renewables"}, {"Entity": "Indonesia", "Year": 2020, "energy": 52.91, "source": "renewables"}, {"Entity": "Italy", "Year": 2000, "energy": 50.87, "source": "renewables"}, {"Entity": "Italy", "Year": 2001, "energy": 54.35, "source": "renewables"}, {"Entity": "Italy", "Year": 2002, "energy": 48.31, "source": "renewables"}, {"Entity": "Italy", "Year": 2003, "energy": 46.86, "source": "renewables"}, {"Entity": "Italy", "Year": 2004, "energy": 53.88, "source": "renewables"}, {"Entity": "Italy", "Year": 2005, "energy": 48.43, "source": "renewables"}, {"Entity": "Italy", "Year": 2006, "energy": 50.64, "source": "renewables"}, {"Entity": "Italy", "Year": 2007, "energy": 47.72, "source": "renewables"}, {"Entity": "Italy", "Year": 2008, "energy": 58.16, "source": "renewables"}, {"Entity": "Italy", "Year": 2009, "energy": 69.26, "source": "renewables"}, {"Entity": "Italy", "Year": 2010, "energy": 76.98, "source": "renewables"}, {"Entity": "Italy", "Year": 2011, "energy": 82.96, "source": "renewables"}, {"Entity": "Italy", "Year": 2012, "energy": 92.22, "source": "renewables"}, {"Entity": "Italy", "Year": 2013, "energy": 112, "source": "renewables"}, {"Entity": "Italy", "Year": 2014, "energy": 120.68, "source": "renewables"}, {"Entity": "Italy", "Year": 2015, "energy": 108.89, "source": "renewables"}, {"Entity": "Italy", "Year": 2016, "energy": 108.01, "source": "renewables"}, {"Entity": "Italy", "Year": 2017, "energy": 103.89, "source": "renewables"}, {"Entity": "Italy", "Year": 2018, "energy": 114.41, "source": "renewables"}, {"Entity": "Italy", "Year": 2019, "energy": 115.83, "source": "renewables"}, {"Entity": "Italy", "Year": 2020, "energy": 116.9, "source": "renewables"}, {"Entity": "Japan", "Year": 2000, "energy": 104.16, "source": "renewables"}, {"Entity": "Japan", "Year": 2001, "energy": 101.36, "source": "renewables"}, {"Entity": "Japan", "Year": 2002, "energy": 101.1, "source": "renewables"}, {"Entity": "Japan", "Year": 2003, "energy": 114.18, "source": "renewables"}, {"Entity": "Japan", "Year": 2004, "energy": 114.73, "source": "renewables"}, {"Entity": "Japan", "Year": 2005, "energy": 100.57, "source": "renewables"}, {"Entity": "Japan", "Year": 2006, "energy": 112.07, "source": "renewables"}, {"Entity": "Japan", "Year": 2007, "energy": 100.8, "source": "renewables"}, {"Entity": "Japan", "Year": 2008, "energy": 100.79, "source": "renewables"}, {"Entity": "Japan", "Year": 2009, "energy": 102.28, "source": "renewables"}, {"Entity": "Japan", "Year": 2010, "energy": 113.92, "source": "renewables"}, {"Entity": "Japan", "Year": 2011, "energy": 116.5, "source": "renewables"}, {"Entity": "Japan", "Year": 2012, "energy": 111.09, "source": "renewables"}, {"Entity": "Japan", "Year": 2013, "energy": 121.48, "source": "renewables"}, {"Entity": "Japan", "Year": 2014, "energy": 136.53, "source": "renewables"}, {"Entity": "Japan", "Year": 2015, "energy": 157.34, "source": "renewables"}, {"Entity": "Japan", "Year": 2016, "energy": 157.7, "source": "renewables"}, {"Entity": "Japan", "Year": 2017, "energy": 175.12, "source": "renewables"}, {"Entity": "Japan", "Year": 2018, "energy": 183.63, "source": "renewables"}, {"Entity": "Japan", "Year": 2019, "energy": 192.72, "source": "renewables"}, {"Entity": "Japan", "Year": 2020, "energy": 205.6, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2000, "energy": 7.53, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2001, "energy": 8.08, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2002, "energy": 8.89, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2003, "energy": 8.62, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2004, "energy": 8.06, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2005, "energy": 7.86, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2006, "energy": 7.77, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2007, "energy": 8.17, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2008, "energy": 7.46, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2009, "energy": 6.88, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2010, "energy": 8.02, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2011, "energy": 7.88, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2012, "energy": 7.64, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2013, "energy": 7.73, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2014, "energy": 8.27, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2015, "energy": 9.45, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2016, "energy": 11.98, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2017, "energy": 11.64, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2018, "energy": 10.91, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2019, "energy": 11.09, "source": "renewables"}, {"Entity": "Kazakhstan", "Year": 2020, "energy": 11.94, "source": "renewables"}, {"Entity": "Mexico", "Year": 2000, "energy": 44.51, "source": "renewables"}, {"Entity": "Mexico", "Year": 2001, "energy": 39.56, "source": "renewables"}, {"Entity": "Mexico", "Year": 2002, "energy": 35.67, "source": "renewables"}, {"Entity": "Mexico", "Year": 2003, "energy": 32.11, "source": "renewables"}, {"Entity": "Mexico", "Year": 2004, "energy": 38.19, "source": "renewables"}, {"Entity": "Mexico", "Year": 2005, "energy": 42.29, "source": "renewables"}, {"Entity": "Mexico", "Year": 2006, "energy": 43.63, "source": "renewables"}, {"Entity": "Mexico", "Year": 2007, "energy": 42.14, "source": "renewables"}, {"Entity": "Mexico", "Year": 2008, "energy": 53.22, "source": "renewables"}, {"Entity": "Mexico", "Year": 2009, "energy": 40.59, "source": "renewables"}, {"Entity": "Mexico", "Year": 2010, "energy": 51.37, "source": "renewables"}, {"Entity": "Mexico", "Year": 2011, "energy": 50.7, "source": "renewables"}, {"Entity": "Mexico", "Year": 2012, "energy": 47.2, "source": "renewables"}, {"Entity": "Mexico", "Year": 2013, "energy": 44.67, "source": "renewables"}, {"Entity": "Mexico", "Year": 2014, "energy": 57.46, "source": "renewables"}, {"Entity": "Mexico", "Year": 2015, "energy": 52.42, "source": "renewables"}, {"Entity": "Mexico", "Year": 2016, "energy": 52.97, "source": "renewables"}, {"Entity": "Mexico", "Year": 2017, "energy": 55.88, "source": "renewables"}, {"Entity": "Mexico", "Year": 2018, "energy": 58.78, "source": "renewables"}, {"Entity": "Mexico", "Year": 2019, "energy": 59, "source": "renewables"}, {"Entity": "Mexico", "Year": 2020, "energy": 69.19, "source": "renewables"}, {"Entity": "Poland", "Year": 2000, "energy": 2.33, "source": "renewables"}, {"Entity": "Poland", "Year": 2001, "energy": 2.78, "source": "renewables"}, {"Entity": "Poland", "Year": 2002, "energy": 2.77, "source": "renewables"}, {"Entity": "Poland", "Year": 2003, "energy": 2.25, "source": "renewables"}, {"Entity": "Poland", "Year": 2004, "energy": 3.2, "source": "renewables"}, {"Entity": "Poland", "Year": 2005, "energy": 3.85, "source": "renewables"}, {"Entity": "Poland", "Year": 2006, "energy": 4.29, "source": "renewables"}, {"Entity": "Poland", "Year": 2007, "energy": 5.43, "source": "renewables"}, {"Entity": "Poland", "Year": 2008, "energy": 6.61, "source": "renewables"}, {"Entity": "Poland", "Year": 2009, "energy": 8.69, "source": "renewables"}, {"Entity": "Poland", "Year": 2010, "energy": 10.88, "source": "renewables"}, {"Entity": "Poland", "Year": 2011, "energy": 13.13, "source": "renewables"}, {"Entity": "Poland", "Year": 2012, "energy": 16.88, "source": "renewables"}, {"Entity": "Poland", "Year": 2013, "energy": 17.06, "source": "renewables"}, {"Entity": "Poland", "Year": 2014, "energy": 19.85, "source": "renewables"}, {"Entity": "Poland", "Year": 2015, "energy": 22.69, "source": "renewables"}, {"Entity": "Poland", "Year": 2016, "energy": 22.81, "source": "renewables"}, {"Entity": "Poland", "Year": 2017, "energy": 24.13, "source": "renewables"}, {"Entity": "Poland", "Year": 2018, "energy": 21.62, "source": "renewables"}, {"Entity": "Poland", "Year": 2019, "energy": 25.46, "source": "renewables"}, {"Entity": "Poland", "Year": 2020, "energy": 28.23, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2000, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2001, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2002, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2003, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2004, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2005, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2006, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2007, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2008, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2009, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2010, "energy": 0, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2011, "energy": 0.01, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2012, "energy": 0.03, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2013, "energy": 0.04, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2014, "energy": 0.05, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2015, "energy": 0.05, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2016, "energy": 0.05, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2017, "energy": 0.07, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2018, "energy": 0.16, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2019, "energy": 0.21, "source": "renewables"}, {"Entity": "Saudi Arabia", "Year": 2020, "energy": 0.21, "source": "renewables"}, {"Entity": "South Africa", "Year": 2000, "energy": 1.79, "source": "renewables"}, {"Entity": "South Africa", "Year": 2001, "energy": 2.46, "source": "renewables"}, {"Entity": "South Africa", "Year": 2002, "energy": 2.81, "source": "renewables"}, {"Entity": "South Africa", "Year": 2003, "energy": 1.19, "source": "renewables"}, {"Entity": "South Africa", "Year": 2004, "energy": 1.33, "source": "renewables"}, {"Entity": "South Africa", "Year": 2005, "energy": 1.75, "source": "renewables"}, {"Entity": "South Africa", "Year": 2006, "energy": 3.28, "source": "renewables"}, {"Entity": "South Africa", "Year": 2007, "energy": 1.3, "source": "renewables"}, {"Entity": "South Africa", "Year": 2008, "energy": 1.66, "source": "renewables"}, {"Entity": "South Africa", "Year": 2009, "energy": 1.86, "source": "renewables"}, {"Entity": "South Africa", "Year": 2010, "energy": 2.51, "source": "renewables"}, {"Entity": "South Africa", "Year": 2011, "energy": 2.49, "source": "renewables"}, {"Entity": "South Africa", "Year": 2012, "energy": 1.66, "source": "renewables"}, {"Entity": "South Africa", "Year": 2013, "energy": 1.62, "source": "renewables"}, {"Entity": "South Africa", "Year": 2014, "energy": 3.38, "source": "renewables"}, {"Entity": "South Africa", "Year": 2015, "energy": 6.09, "source": "renewables"}, {"Entity": "South Africa", "Year": 2016, "energy": 7.69, "source": "renewables"}, {"Entity": "South Africa", "Year": 2017, "energy": 10.04, "source": "renewables"}, {"Entity": "South Africa", "Year": 2018, "energy": 12.22, "source": "renewables"}, {"Entity": "South Africa", "Year": 2019, "energy": 12.57, "source": "renewables"}, {"Entity": "South Africa", "Year": 2020, "energy": 12.83, "source": "renewables"}, {"Entity": "Spain", "Year": 2000, "energy": 34.49, "source": "renewables"}, {"Entity": "Spain", "Year": 2001, "energy": 49.3, "source": "renewables"}, {"Entity": "Spain", "Year": 2002, "energy": 33.17, "source": "renewables"}, {"Entity": "Spain", "Year": 2003, "energy": 55.75, "source": "renewables"}, {"Entity": "Spain", "Year": 2004, "energy": 50.13, "source": "renewables"}, {"Entity": "Spain", "Year": 2005, "energy": 42.27, "source": "renewables"}, {"Entity": "Spain", "Year": 2006, "energy": 52.15, "source": "renewables"}, {"Entity": "Spain", "Year": 2007, "energy": 58.3, "source": "renewables"}, {"Entity": "Spain", "Year": 2008, "energy": 62.15, "source": "renewables"}, {"Entity": "Spain", "Year": 2009, "energy": 74.08, "source": "renewables"}, {"Entity": "Spain", "Year": 2010, "energy": 97.77, "source": "renewables"}, {"Entity": "Spain", "Year": 2011, "energy": 87.53, "source": "renewables"}, {"Entity": "Spain", "Year": 2012, "energy": 86.97, "source": "renewables"}, {"Entity": "Spain", "Year": 2013, "energy": 111.42, "source": "renewables"}, {"Entity": "Spain", "Year": 2014, "energy": 110.26, "source": "renewables"}, {"Entity": "Spain", "Year": 2015, "energy": 97.09, "source": "renewables"}, {"Entity": "Spain", "Year": 2016, "energy": 104.63, "source": "renewables"}, {"Entity": "Spain", "Year": 2017, "energy": 87.93, "source": "renewables"}, {"Entity": "Spain", "Year": 2018, "energy": 103.88, "source": "renewables"}, {"Entity": "Spain", "Year": 2019, "energy": 100.99, "source": "renewables"}, {"Entity": "Spain", "Year": 2020, "energy": 113.79, "source": "renewables"}, {"Entity": "Thailand", "Year": 2000, "energy": 6.38, "source": "renewables"}, {"Entity": "Thailand", "Year": 2001, "energy": 6.76, "source": "renewables"}, {"Entity": "Thailand", "Year": 2002, "energy": 8.07, "source": "renewables"}, {"Entity": "Thailand", "Year": 2003, "energy": 8.36, "source": "renewables"}, {"Entity": "Thailand", "Year": 2004, "energy": 7.63, "source": "renewables"}, {"Entity": "Thailand", "Year": 2005, "energy": 7.42, "source": "renewables"}, {"Entity": "Thailand", "Year": 2006, "energy": 9.82, "source": "renewables"}, {"Entity": "Thailand", "Year": 2007, "energy": 10.2, "source": "renewables"}, {"Entity": "Thailand", "Year": 2008, "energy": 8.95, "source": "renewables"}, {"Entity": "Thailand", "Year": 2009, "energy": 9.09, "source": "renewables"}, {"Entity": "Thailand", "Year": 2010, "energy": 8.58, "source": "renewables"}, {"Entity": "Thailand", "Year": 2011, "energy": 11.83, "source": "renewables"}, {"Entity": "Thailand", "Year": 2012, "energy": 13.42, "source": "renewables"}, {"Entity": "Thailand", "Year": 2013, "energy": 12.33, "source": "renewables"}, {"Entity": "Thailand", "Year": 2014, "energy": 13.68, "source": "renewables"}, {"Entity": "Thailand", "Year": 2015, "energy": 13.33, "source": "renewables"}, {"Entity": "Thailand", "Year": 2016, "energy": 15.97, "source": "renewables"}, {"Entity": "Thailand", "Year": 2017, "energy": 19.92, "source": "renewables"}, {"Entity": "Thailand", "Year": 2018, "energy": 25.84, "source": "renewables"}, {"Entity": "Thailand", "Year": 2019, "energy": 28.02, "source": "renewables"}, {"Entity": "Thailand", "Year": 2020, "energy": 24.73, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2000, "energy": 11.28, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2001, "energy": 12.05, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2002, "energy": 9.65, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2003, "energy": 9.27, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2004, "energy": 11.78, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2005, "energy": 12.4, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2006, "energy": 12.92, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2007, "energy": 10.47, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2008, "energy": 11.82, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2009, "energy": 12.12, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2010, "energy": 13.39, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2011, "energy": 11.2, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2012, "energy": 11.23, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2013, "energy": 15.11, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2014, "energy": 10.17, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2015, "energy": 7.1, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2016, "energy": 9.25, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2017, "energy": 10.88, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2018, "energy": 13.02, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2019, "energy": 11.87, "source": "renewables"}, {"Entity": "Ukraine", "Year": 2020, "energy": 17.56, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2000, "energy": 9.98, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2001, "energy": 9.56, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2002, "energy": 11.13, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2003, "energy": 10.62, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2004, "energy": 14.14, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2005, "energy": 16.93, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2006, "energy": 18.11, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2007, "energy": 19.69, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2008, "energy": 21.85, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2009, "energy": 25.25, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2010, "energy": 26.18, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2011, "energy": 35.2, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2012, "energy": 41.24, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2013, "energy": 53.21, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2014, "energy": 64.52, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2015, "energy": 82.57, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2016, "energy": 82.99, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2017, "energy": 98.85, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2018, "energy": 110.03, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2019, "energy": 120.48, "source": "renewables"}, {"Entity": "United Kingdom", "Year": 2020, "energy": 131.74, "source": "renewables"}, {"Entity": "United States", "Year": 2000, "energy": 350.93, "source": "renewables"}, {"Entity": "United States", "Year": 2001, "energy": 280.06, "source": "renewables"}, {"Entity": "United States", "Year": 2002, "energy": 336.34, "source": "renewables"}, {"Entity": "United States", "Year": 2003, "energy": 349.18, "source": "renewables"}, {"Entity": "United States", "Year": 2004, "energy": 345.14, "source": "renewables"}, {"Entity": "United States", "Year": 2005, "energy": 353.04, "source": "renewables"}, {"Entity": "United States", "Year": 2006, "energy": 381.16, "source": "renewables"}, {"Entity": "United States", "Year": 2007, "energy": 347.91, "source": "renewables"}, {"Entity": "United States", "Year": 2008, "energy": 377.11, "source": "renewables"}, {"Entity": "United States", "Year": 2009, "energy": 415.56, "source": "renewables"}, {"Entity": "United States", "Year": 2010, "energy": 424.48, "source": "renewables"}, {"Entity": "United States", "Year": 2011, "energy": 509.74, "source": "renewables"}, {"Entity": "United States", "Year": 2012, "energy": 492.32, "source": "renewables"}, {"Entity": "United States", "Year": 2013, "energy": 520.38, "source": "renewables"}, {"Entity": "United States", "Year": 2014, "energy": 546.83, "source": "renewables"}, {"Entity": "United States", "Year": 2015, "energy": 556.49, "source": "renewables"}, {"Entity": "United States", "Year": 2016, "energy": 624.91, "source": "renewables"}, {"Entity": "United States", "Year": 2017, "energy": 707.19, "source": "renewables"}, {"Entity": "United States", "Year": 2018, "energy": 733.17, "source": "renewables"}, {"Entity": "United States", "Year": 2019, "energy": 760.76, "source": "renewables"}, {"Entity": "United States", "Year": 2020, "energy": 821.4, "source": "renewables"}], "metadata": {"Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}, "energy": {"type": "number", "semanticType": "Number"}, "source": {"type": "string", "semanticType": "String", "levels": ["fossil fuels", "nuclear", "renewables"]}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 158029.9988, 190729.9957, 209229.9957, ..., 6993180.176, 9861099.609, 9874660.156, 10096009.77\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 90.14, 91.79, 92.54, 804.95\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Transform the data into a long format where different energy sources (fossil fuels, nuclear, renewables) are unpivoted into separate rows. Each row should contain the year, entity (country), energy source type, and the corresponding energy value in TWh. This will enable visualization of energy generation trends over time by source and country.\",\n \"display_instruction\": \"Show **energy generation** trends by **source** and **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"source\", \"energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n },\n \"reason\": \"The user wants to visualize energy data across different sources with a line chart faceted by source. The original data has energy sources in separate columns (fossil fuels, nuclear, renewables), so we need to unpivot these columns into a long format with 'source' and 'energy' fields. The chart_encodings provided by the user are appropriate for this visualization goal, using faceting (column) to separate different energy sources.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "global-energy-20-small.csv", "resultTableId": "table-82", "chart": {"id": "chart-1760738394155", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"channel": "y", "bin": false, "fieldID": "concept-1760738385163"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {"channel": "column", "bin": false, "fieldID": "concept-1760738389404"}, "row": {"channel": "row", "bin": false}}, "tableRef": "global-energy-20-small.csv", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "", "displayContent": "Show **energy generation** trends by **source** and **Entity** over **Year**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code performs a data transformation to restructure the energy data from a wide format to a long format:\n\n1. **Unpivot energy columns**: Uses `pd.melt()` to transform the three energy source columns (**Electricity from fossil fuels**, **Electricity from nuclear**, and **Electricity from renewables**) from separate columns into rows, while keeping **Year** and **Entity** as identifier columns.\n\n2. **Create source classification**: Generates a new **source** column that captures which energy type each row represents, and stores the corresponding energy values in an **energy** column.\n\n3. **Clean source labels**: Removes the prefix \"Electricity from \" and suffix \" (TWh)\" from the source names, resulting in cleaner labels: **fossil fuels**, **nuclear**, and **renewables**.\n\n4. **Return restructured data**: The final dataset has each country-year-energy source combination as a separate row, making it easier to analyze and visualize energy mix across countries and time periods.", "concepts": [], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 190729.9957, 227580.0018, 233600.0061, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 90.14, 91.79, 92.54, nan\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code performs a data transformation to restructure the energy data from a wide format to a long format:\n\n1. **Unpivot energy columns**: Uses `pd.melt()` to transform the three energy source columns (**Electricity from fossil fuels**, **Electricity from nuclear**, and **Electricity from renewables**) from separate columns into rows, while keeping **Year** and **Entity** as identifier columns.\n\n2. **Create source classification**: Generates a new **source** column that captures which energy type each row represents, and stores the corresponding energy values in an **energy** column.\n\n3. **Clean source labels**: Removes the prefix \"Electricity from \" and suffix \" (TWh)\" from the source names, resulting in cleaner labels: **fossil fuels**, **nuclear**, and **renewables**.\n\n4. **Return restructured data**: The final dataset has each country-year-energy source combination as a separate row, making it easier to analyze and visualize energy mix across countries and time periods.\n\n[CONCEPTS EXPLANATION]\n\n```json\n[]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-45", "displayId": "renewable-energy", "names": ["Entity", "Year", "renewable_percentage"], "rows": [{"Entity": "Australia", "Year": 2000, "renewable_percentage": 8.6344368187}, {"Entity": "Australia", "Year": 2001, "renewable_percentage": 8.2180135078}, {"Entity": "Australia", "Year": 2002, "renewable_percentage": 8.0833022736}, {"Entity": "Australia", "Year": 2003, "renewable_percentage": 8.6598324205}, {"Entity": "Australia", "Year": 2004, "renewable_percentage": 8.7013045232}, {"Entity": "Australia", "Year": 2005, "renewable_percentage": 9.1562355123}, {"Entity": "Australia", "Year": 2006, "renewable_percentage": 9.6357600837}, {"Entity": "Australia", "Year": 2007, "renewable_percentage": 9.1190310213}, {"Entity": "Australia", "Year": 2008, "renewable_percentage": 8.0548900022}, {"Entity": "Australia", "Year": 2009, "renewable_percentage": 7.8043793133}, {"Entity": "Australia", "Year": 2010, "renewable_percentage": 9.0442152121}, {"Entity": "Australia", "Year": 2011, "renewable_percentage": 11.3454273735}, {"Entity": "Australia", "Year": 2012, "renewable_percentage": 11.4105750279}, {"Entity": "Australia", "Year": 2013, "renewable_percentage": 14.8708583355}, {"Entity": "Australia", "Year": 2014, "renewable_percentage": 14.9621290509}, {"Entity": "Australia", "Year": 2015, "renewable_percentage": 14.3476000693}, {"Entity": "Australia", "Year": 2016, "renewable_percentage": 15.6093794449}, {"Entity": "Australia", "Year": 2017, "renewable_percentage": 16.3138729943}, {"Entity": "Australia", "Year": 2018, "renewable_percentage": 17.145938174}, {"Entity": "Australia", "Year": 2019, "renewable_percentage": 21.3759705435}, {"Entity": "Australia", "Year": 2020, "renewable_percentage": 25.5031684668}, {"Entity": "Brazil", "Year": 2000, "renewable_percentage": 90.1307723743}, {"Entity": "Brazil", "Year": 2001, "renewable_percentage": 84.6953615744}, {"Entity": "Brazil", "Year": 2002, "renewable_percentage": 86.0883364189}, {"Entity": "Brazil", "Year": 2003, "renewable_percentage": 87.4561159097}, {"Entity": "Brazil", "Year": 2004, "renewable_percentage": 86.4260041451}, {"Entity": "Brazil", "Year": 2005, "renewable_percentage": 87.6781562721}, {"Entity": "Brazil", "Year": 2006, "renewable_percentage": 87.2842473236}, {"Entity": "Brazil", "Year": 2007, "renewable_percentage": 88.7252098726}, {"Entity": "Brazil", "Year": 2008, "renewable_percentage": 84.8072313004}, {"Entity": "Brazil", "Year": 2009, "renewable_percentage": 89.4172280725}, {"Entity": "Brazil", "Year": 2010, "renewable_percentage": 85.3576882415}, {"Entity": "Brazil", "Year": 2011, "renewable_percentage": 87.6618820986}, {"Entity": "Brazil", "Year": 2012, "renewable_percentage": 83.1164558813}, {"Entity": "Brazil", "Year": 2013, "renewable_percentage": 77.5240022006}, {"Entity": "Brazil", "Year": 2014, "renewable_percentage": 74.0418657409}, {"Entity": "Brazil", "Year": 2015, "renewable_percentage": 75.0231817625}, {"Entity": "Brazil", "Year": 2016, "renewable_percentage": 81.0938046902}, {"Entity": "Brazil", "Year": 2017, "renewable_percentage": 79.9091472228}, {"Entity": "Brazil", "Year": 2018, "renewable_percentage": 82.9198505403}, {"Entity": "Brazil", "Year": 2019, "renewable_percentage": 82.8548799017}, {"Entity": "Brazil", "Year": 2020, "renewable_percentage": 84.6411771408}, {"Entity": "Canada", "Year": 2000, "renewable_percentage": 61.8095917882}, {"Entity": "Canada", "Year": 2001, "renewable_percentage": 59.3287558747}, {"Entity": "Canada", "Year": 2002, "renewable_percentage": 61.1477403113}, {"Entity": "Canada", "Year": 2003, "renewable_percentage": 60.0789685174}, {"Entity": "Canada", "Year": 2004, "renewable_percentage": 59.6967771845}, {"Entity": "Canada", "Year": 2005, "renewable_percentage": 60.8208155391}, {"Entity": "Canada", "Year": 2006, "renewable_percentage": 60.8271602855}, {"Entity": "Canada", "Year": 2007, "renewable_percentage": 61.2460642446}, {"Entity": "Canada", "Year": 2008, "renewable_percentage": 62.6520720838}, {"Entity": "Canada", "Year": 2009, "renewable_percentage": 63.8919227732}, {"Entity": "Canada", "Year": 2010, "renewable_percentage": 62.9421470558}, {"Entity": "Canada", "Year": 2011, "renewable_percentage": 64.0922915917}, {"Entity": "Canada", "Year": 2012, "renewable_percentage": 65.098730952}, {"Entity": "Canada", "Year": 2013, "renewable_percentage": 65.4320794066}, {"Entity": "Canada", "Year": 2014, "renewable_percentage": 64.791145907}, {"Entity": "Canada", "Year": 2015, "renewable_percentage": 65.2946239925}, {"Entity": "Canada", "Year": 2016, "renewable_percentage": 66.1890584295}, {"Entity": "Canada", "Year": 2017, "renewable_percentage": 67.5399410579}, {"Entity": "Canada", "Year": 2018, "renewable_percentage": 67.3685700357}, {"Entity": "Canada", "Year": 2019, "renewable_percentage": 67.1741623137}, {"Entity": "Canada", "Year": 2020, "renewable_percentage": 68.7796436354}, {"Entity": "China", "Year": 2000, "renewable_percentage": 16.639126586}, {"Entity": "China", "Year": 2001, "renewable_percentage": 18.9581237042}, {"Entity": "China", "Year": 2002, "renewable_percentage": 17.6185006046}, {"Entity": "China", "Year": 2003, "renewable_percentage": 15.0362717081}, {"Entity": "China", "Year": 2004, "renewable_percentage": 16.2224108273}, {"Entity": "China", "Year": 2005, "renewable_percentage": 16.1731179957}, {"Entity": "China", "Year": 2006, "renewable_percentage": 15.5884036124}, {"Entity": "China", "Year": 2007, "renewable_percentage": 15.2583847828}, {"Entity": "China", "Year": 2008, "renewable_percentage": 19.0253335469}, {"Entity": "China", "Year": 2009, "renewable_percentage": 17.8857170547}, {"Entity": "China", "Year": 2010, "renewable_percentage": 18.7800759915}, {"Entity": "China", "Year": 2011, "renewable_percentage": 16.8902341543}, {"Entity": "China", "Year": 2012, "renewable_percentage": 20.122965176}, {"Entity": "China", "Year": 2013, "renewable_percentage": 20.2152481955}, {"Entity": "China", "Year": 2014, "renewable_percentage": 22.3502204285}, {"Entity": "China", "Year": 2015, "renewable_percentage": 24.079270189}, {"Entity": "China", "Year": 2016, "renewable_percentage": 25.0007798429}, {"Entity": "China", "Year": 2017, "renewable_percentage": 25.419242299}, {"Entity": "China", "Year": 2018, "renewable_percentage": 25.7747942589}, {"Entity": "China", "Year": 2019, "renewable_percentage": 26.9995671106}, {"Entity": "China", "Year": 2020, "renewable_percentage": 28.2464606924}, {"Entity": "France", "Year": 2000, "renewable_percentage": 12.7117691154}, {"Entity": "France", "Year": 2001, "renewable_percentage": 13.9961372206}, {"Entity": "France", "Year": 2002, "renewable_percentage": 11.3544157067}, {"Entity": "France", "Year": 2003, "renewable_percentage": 10.9783540506}, {"Entity": "France", "Year": 2004, "renewable_percentage": 11.0051305559}, {"Entity": "France", "Year": 2005, "renewable_percentage": 9.6479837153}, {"Entity": "France", "Year": 2006, "renewable_percentage": 10.7235915493}, {"Entity": "France", "Year": 2007, "renewable_percentage": 11.4370075239}, {"Entity": "France", "Year": 2008, "renewable_percentage": 12.7487441615}, {"Entity": "France", "Year": 2009, "renewable_percentage": 12.8776856068}, {"Entity": "France", "Year": 2010, "renewable_percentage": 13.6240072491}, {"Entity": "France", "Year": 2011, "renewable_percentage": 11.63553049}, {"Entity": "France", "Year": 2012, "renewable_percentage": 15.0331522889}, {"Entity": "France", "Year": 2013, "renewable_percentage": 17.2469424928}, {"Entity": "France", "Year": 2014, "renewable_percentage": 16.6074992494}, {"Entity": "France", "Year": 2015, "renewable_percentage": 16.002230276}, {"Entity": "France", "Year": 2016, "renewable_percentage": 17.7212924013}, {"Entity": "France", "Year": 2017, "renewable_percentage": 16.6576751547}, {"Entity": "France", "Year": 2018, "renewable_percentage": 19.7315179827}, {"Entity": "France", "Year": 2019, "renewable_percentage": 20.0116665488}, {"Entity": "France", "Year": 2020, "renewable_percentage": 23.7610241821}, {"Entity": "Germany", "Year": 2000, "renewable_percentage": 6.1977983575}, {"Entity": "Germany", "Year": 2001, "renewable_percentage": 6.5132585197}, {"Entity": "Germany", "Year": 2002, "renewable_percentage": 7.6431369854}, {"Entity": "Germany", "Year": 2003, "renewable_percentage": 7.7455438643}, {"Entity": "Germany", "Year": 2004, "renewable_percentage": 9.4989185292}, {"Entity": "Germany", "Year": 2005, "renewable_percentage": 10.3356645637}, {"Entity": "Germany", "Year": 2006, "renewable_percentage": 11.5129959829}, {"Entity": "Germany", "Year": 2007, "renewable_percentage": 14.135471525}, {"Entity": "Germany", "Year": 2008, "renewable_percentage": 14.8894504106}, {"Entity": "Germany", "Year": 2009, "renewable_percentage": 16.2902842395}, {"Entity": "Germany", "Year": 2010, "renewable_percentage": 16.8384989754}, {"Entity": "Germany", "Year": 2011, "renewable_percentage": 20.4967199299}, {"Entity": "Germany", "Year": 2012, "renewable_percentage": 23.056464482}, {"Entity": "Germany", "Year": 2013, "renewable_percentage": 24.1368929731}, {"Entity": "Germany", "Year": 2014, "renewable_percentage": 26.2182434067}, {"Entity": "Germany", "Year": 2015, "renewable_percentage": 29.4721888318}, {"Entity": "Germany", "Year": 2016, "renewable_percentage": 29.4990435013}, {"Entity": "Germany", "Year": 2017, "renewable_percentage": 33.4855497593}, {"Entity": "Germany", "Year": 2018, "renewable_percentage": 35.0976735365}, {"Entity": "Germany", "Year": 2019, "renewable_percentage": 40.0890757144}, {"Entity": "Germany", "Year": 2020, "renewable_percentage": 44.3324048937}, {"Entity": "India", "Year": 2000, "renewable_percentage": 14.0481982534}, {"Entity": "India", "Year": 2001, "renewable_percentage": 12.9997099422}, {"Entity": "India", "Year": 2002, "renewable_percentage": 11.938193032}, {"Entity": "India", "Year": 2003, "renewable_percentage": 11.695109147}, {"Entity": "India", "Year": 2004, "renewable_percentage": 15.6375300722}, {"Entity": "India", "Year": 2005, "renewable_percentage": 15.2543575768}, {"Entity": "India", "Year": 2006, "renewable_percentage": 17.1352578483}, {"Entity": "India", "Year": 2007, "renewable_percentage": 17.8019742295}, {"Entity": "India", "Year": 2008, "renewable_percentage": 16.768266921}, {"Entity": "India", "Year": 2009, "renewable_percentage": 15.269804822}, {"Entity": "India", "Year": 2010, "renewable_percentage": 15.2122201244}, {"Entity": "India", "Year": 2011, "renewable_percentage": 16.7911025145}, {"Entity": "India", "Year": 2012, "renewable_percentage": 15.1350014654}, {"Entity": "India", "Year": 2013, "renewable_percentage": 16.3941577818}, {"Entity": "India", "Year": 2014, "renewable_percentage": 16.0092550039}, {"Entity": "India", "Year": 2015, "renewable_percentage": 15.3718720687}, {"Entity": "India", "Year": 2016, "renewable_percentage": 14.8548475703}, {"Entity": "India", "Year": 2017, "renewable_percentage": 15.9669920335}, {"Entity": "India", "Year": 2018, "renewable_percentage": 16.6949549709}, {"Entity": "India", "Year": 2019, "renewable_percentage": 18.6915426873}, {"Entity": "India", "Year": 2020, "renewable_percentage": 20.2059243238}, {"Entity": "Indonesia", "Year": 2000, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2001, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2002, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2003, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2004, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2005, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2006, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2007, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2008, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2009, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2010, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2011, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2012, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2013, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2014, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2015, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2016, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2017, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2018, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2019, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2020, "renewable_percentage": null}, {"Entity": "Italy", "Year": 2000, "renewable_percentage": 18.900241501}, {"Entity": "Italy", "Year": 2001, "renewable_percentage": 20.049431902}, {"Entity": "Italy", "Year": 2002, "renewable_percentage": 17.4555571614}, {"Entity": "Italy", "Year": 2003, "renewable_percentage": 16.4202116476}, {"Entity": "Italy", "Year": 2004, "renewable_percentage": 18.2749380999}, {"Entity": "Italy", "Year": 2005, "renewable_percentage": 16.3769782226}, {"Entity": "Italy", "Year": 2006, "renewable_percentage": 16.5128639906}, {"Entity": "Italy", "Year": 2007, "renewable_percentage": 15.5333485238}, {"Entity": "Italy", "Year": 2008, "renewable_percentage": 18.6112}, {"Entity": "Italy", "Year": 2009, "renewable_percentage": 24.0837332221}, {"Entity": "Italy", "Year": 2010, "renewable_percentage": 25.8400187976}, {"Entity": "Italy", "Year": 2011, "renewable_percentage": 27.6773203443}, {"Entity": "Italy", "Year": 2012, "renewable_percentage": 31.1049649217}, {"Entity": "Italy", "Year": 2013, "renewable_percentage": 39.0148744209}, {"Entity": "Italy", "Year": 2014, "renewable_percentage": 43.4976931949}, {"Entity": "Italy", "Year": 2015, "renewable_percentage": 38.7577860829}, {"Entity": "Italy", "Year": 2016, "renewable_percentage": 37.6079387187}, {"Entity": "Italy", "Year": 2017, "renewable_percentage": 35.4174479255}, {"Entity": "Italy", "Year": 2018, "renewable_percentage": 39.8100142663}, {"Entity": "Italy", "Year": 2019, "renewable_percentage": 39.7563068474}, {"Entity": "Italy", "Year": 2020, "renewable_percentage": 42.0397741576}, {"Entity": "Japan", "Year": 2000, "renewable_percentage": 10.5382436261}, {"Entity": "Japan", "Year": 2001, "renewable_percentage": 10.447653504}, {"Entity": "Japan", "Year": 2002, "renewable_percentage": 10.2477294843}, {"Entity": "Japan", "Year": 2003, "renewable_percentage": 11.6993698448}, {"Entity": "Japan", "Year": 2004, "renewable_percentage": 11.4198974767}, {"Entity": "Japan", "Year": 2005, "renewable_percentage": 9.9068127192}, {"Entity": "Japan", "Year": 2006, "renewable_percentage": 10.8554989442}, {"Entity": "Japan", "Year": 2007, "renewable_percentage": 9.3897588285}, {"Entity": "Japan", "Year": 2008, "renewable_percentage": 10.0196834738}, {"Entity": "Japan", "Year": 2009, "renewable_percentage": 10.4667464874}, {"Entity": "Japan", "Year": 2010, "renewable_percentage": 10.5269966826}, {"Entity": "Japan", "Year": 2011, "renewable_percentage": 11.1272421632}, {"Entity": "Japan", "Year": 2012, "renewable_percentage": 10.6143703421}, {"Entity": "Japan", "Year": 2013, "renewable_percentage": 11.7965798852}, {"Entity": "Japan", "Year": 2014, "renewable_percentage": 13.2719619718}, {"Entity": "Japan", "Year": 2015, "renewable_percentage": 15.6586817408}, {"Entity": "Japan", "Year": 2016, "renewable_percentage": 15.6920107068}, {"Entity": "Japan", "Year": 2017, "renewable_percentage": 17.3559698312}, {"Entity": "Japan", "Year": 2018, "renewable_percentage": 18.144181175}, {"Entity": "Japan", "Year": 2019, "renewable_percentage": 19.4223288251}, {"Entity": "Japan", "Year": 2020, "renewable_percentage": 21.324925062}, {"Entity": "Kazakhstan", "Year": 2000, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2001, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2002, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2003, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2004, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2005, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2006, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2007, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2008, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2009, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2010, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2011, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2012, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2013, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2014, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2015, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2016, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2017, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2018, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2019, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2020, "renewable_percentage": null}, {"Entity": "Mexico", "Year": 2000, "renewable_percentage": 22.9291160107}, {"Entity": "Mexico", "Year": 2001, "renewable_percentage": 19.6649599841}, {"Entity": "Mexico", "Year": 2002, "renewable_percentage": 17.4220963173}, {"Entity": "Mexico", "Year": 2003, "renewable_percentage": 15.8536585366}, {"Entity": "Mexico", "Year": 2004, "renewable_percentage": 17.3134463687}, {"Entity": "Mexico", "Year": 2005, "renewable_percentage": 18.2780827246}, {"Entity": "Mexico", "Year": 2006, "renewable_percentage": 18.4256091896}, {"Entity": "Mexico", "Year": 2007, "renewable_percentage": 17.2761561168}, {"Entity": "Mexico", "Year": 2008, "renewable_percentage": 21.5387105913}, {"Entity": "Mexico", "Year": 2009, "renewable_percentage": 16.5369729069}, {"Entity": "Mexico", "Year": 2010, "renewable_percentage": 19.4281608109}, {"Entity": "Mexico", "Year": 2011, "renewable_percentage": 18.0916357408}, {"Entity": "Mexico", "Year": 2012, "renewable_percentage": 16.5759438104}, {"Entity": "Mexico", "Year": 2013, "renewable_percentage": 15.5492898914}, {"Entity": "Mexico", "Year": 2014, "renewable_percentage": 19.8008201523}, {"Entity": "Mexico", "Year": 2015, "renewable_percentage": 17.5976903451}, {"Entity": "Mexico", "Year": 2016, "renewable_percentage": 17.4806943436}, {"Entity": "Mexico", "Year": 2017, "renewable_percentage": 18.0759526428}, {"Entity": "Mexico", "Year": 2018, "renewable_percentage": 17.703752786}, {"Entity": "Mexico", "Year": 2019, "renewable_percentage": 18.5487927565}, {"Entity": "Mexico", "Year": 2020, "renewable_percentage": 21.2552224134}, {"Entity": "Poland", "Year": 2000, "renewable_percentage": 1.6273222517}, {"Entity": "Poland", "Year": 2001, "renewable_percentage": 1.934316727}, {"Entity": "Poland", "Year": 2002, "renewable_percentage": 1.9439960699}, {"Entity": "Poland", "Year": 2003, "renewable_percentage": 1.4999000067}, {"Entity": "Poland", "Year": 2004, "renewable_percentage": 2.1016681991}, {"Entity": "Poland", "Year": 2005, "renewable_percentage": 2.4830699774}, {"Entity": "Poland", "Year": 2006, "renewable_percentage": 2.673730134}, {"Entity": "Poland", "Year": 2007, "renewable_percentage": 3.4256513785}, {"Entity": "Poland", "Year": 2008, "renewable_percentage": 4.2744438696}, {"Entity": "Poland", "Year": 2009, "renewable_percentage": 5.7515388179}, {"Entity": "Poland", "Year": 2010, "renewable_percentage": 6.9299363057}, {"Entity": "Poland", "Year": 2011, "renewable_percentage": 8.0547205693}, {"Entity": "Poland", "Year": 2012, "renewable_percentage": 10.4436057663}, {"Entity": "Poland", "Year": 2013, "renewable_percentage": 10.4081508145}, {"Entity": "Poland", "Year": 2014, "renewable_percentage": 12.5331481248}, {"Entity": "Poland", "Year": 2015, "renewable_percentage": 13.8151485631}, {"Entity": "Poland", "Year": 2016, "renewable_percentage": 13.7335179722}, {"Entity": "Poland", "Year": 2017, "renewable_percentage": 14.1999646913}, {"Entity": "Poland", "Year": 2018, "renewable_percentage": 12.7559148032}, {"Entity": "Poland", "Year": 2019, "renewable_percentage": 15.6157998037}, {"Entity": "Poland", "Year": 2020, "renewable_percentage": 17.9648720886}, {"Entity": "Saudi Arabia", "Year": 2000, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2001, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2002, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2003, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2004, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2005, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2006, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2007, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2008, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2009, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2010, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2011, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2012, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2013, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2014, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2015, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2016, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2017, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2018, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2019, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2020, "renewable_percentage": null}, {"Entity": "South Africa", "Year": 2000, "renewable_percentage": 0.9110805721}, {"Entity": "South Africa", "Year": 2001, "renewable_percentage": 1.2516536074}, {"Entity": "South Africa", "Year": 2002, "renewable_percentage": 1.3802249619}, {"Entity": "South Africa", "Year": 2003, "renewable_percentage": 0.545271261}, {"Entity": "South Africa", "Year": 2004, "renewable_percentage": 0.5827199439}, {"Entity": "South Africa", "Year": 2005, "renewable_percentage": 0.763458686}, {"Entity": "South Africa", "Year": 2006, "renewable_percentage": 1.3863060017}, {"Entity": "South Africa", "Year": 2007, "renewable_percentage": 0.5267209594}, {"Entity": "South Africa", "Year": 2008, "renewable_percentage": 0.6895692269}, {"Entity": "South Africa", "Year": 2009, "renewable_percentage": 0.8031088083}, {"Entity": "South Africa", "Year": 2010, "renewable_percentage": 1.0330068318}, {"Entity": "South Africa", "Year": 2011, "renewable_percentage": 1.0184465622}, {"Entity": "South Africa", "Year": 2012, "renewable_percentage": 0.6890826069}, {"Entity": "South Africa", "Year": 2013, "renewable_percentage": 0.6792168043}, {"Entity": "South Africa", "Year": 2014, "renewable_percentage": 1.4288129861}, {"Entity": "South Africa", "Year": 2015, "renewable_percentage": 2.6256790549}, {"Entity": "South Africa", "Year": 2016, "renewable_percentage": 3.2586126531}, {"Entity": "South Africa", "Year": 2017, "renewable_percentage": 4.2202606137}, {"Entity": "South Africa", "Year": 2018, "renewable_percentage": 5.1554655529}, {"Entity": "South Africa", "Year": 2019, "renewable_percentage": 5.3589699864}, {"Entity": "South Africa", "Year": 2020, "renewable_percentage": 5.780581212}, {"Entity": "Spain", "Year": 2000, "renewable_percentage": 15.6119862394}, {"Entity": "Spain", "Year": 2001, "renewable_percentage": 21.1524434719}, {"Entity": "Spain", "Year": 2002, "renewable_percentage": 13.8260180901}, {"Entity": "Spain", "Year": 2003, "renewable_percentage": 21.667314419}, {"Entity": "Spain", "Year": 2004, "renewable_percentage": 18.3190206468}, {"Entity": "Spain", "Year": 2005, "renewable_percentage": 14.8597342333}, {"Entity": "Spain", "Year": 2006, "renewable_percentage": 17.6623992413}, {"Entity": "Spain", "Year": 2007, "renewable_percentage": 19.3347262296}, {"Entity": "Spain", "Year": 2008, "renewable_percentage": 20.0051501593}, {"Entity": "Spain", "Year": 2009, "renewable_percentage": 25.4107639008}, {"Entity": "Spain", "Year": 2010, "renewable_percentage": 32.7922186819}, {"Entity": "Spain", "Year": 2011, "renewable_percentage": 30.0408415417}, {"Entity": "Spain", "Year": 2012, "renewable_percentage": 29.6047928652}, {"Entity": "Spain", "Year": 2013, "renewable_percentage": 39.5850357054}, {"Entity": "Spain", "Year": 2014, "renewable_percentage": 40.1032952644}, {"Entity": "Spain", "Year": 2015, "renewable_percentage": 34.9899091826}, {"Entity": "Spain", "Year": 2016, "renewable_percentage": 38.5818061138}, {"Entity": "Spain", "Year": 2017, "renewable_percentage": 32.220593624}, {"Entity": "Spain", "Year": 2018, "renewable_percentage": 38.2080329557}, {"Entity": "Spain", "Year": 2019, "renewable_percentage": 37.280815091}, {"Entity": "Spain", "Year": 2020, "renewable_percentage": 43.8108805298}, {"Entity": "Thailand", "Year": 2000, "renewable_percentage": 7.1261029822}, {"Entity": "Thailand", "Year": 2001, "renewable_percentage": 7.061527212}, {"Entity": "Thailand", "Year": 2002, "renewable_percentage": 7.9444772593}, {"Entity": "Thailand", "Year": 2003, "renewable_percentage": 7.6718362852}, {"Entity": "Thailand", "Year": 2004, "renewable_percentage": 6.5163549406}, {"Entity": "Thailand", "Year": 2005, "renewable_percentage": 6.0325203252}, {"Entity": "Thailand", "Year": 2006, "renewable_percentage": 7.5988547551}, {"Entity": "Thailand", "Year": 2007, "renewable_percentage": 7.7085852479}, {"Entity": "Thailand", "Year": 2008, "renewable_percentage": 6.5625458278}, {"Entity": "Thailand", "Year": 2009, "renewable_percentage": 6.6263303689}, {"Entity": "Thailand", "Year": 2010, "renewable_percentage": 5.7085828343}, {"Entity": "Thailand", "Year": 2011, "renewable_percentage": 8.039961941}, {"Entity": "Thailand", "Year": 2012, "renewable_percentage": 8.5396118358}, {"Entity": "Thailand", "Year": 2013, "renewable_percentage": 7.6765035487}, {"Entity": "Thailand", "Year": 2014, "renewable_percentage": 8.395728489}, {"Entity": "Thailand", "Year": 2015, "renewable_percentage": 7.9949619145}, {"Entity": "Thailand", "Year": 2016, "renewable_percentage": 8.9840234023}, {"Entity": "Thailand", "Year": 2017, "renewable_percentage": 10.9570957096}, {"Entity": "Thailand", "Year": 2018, "renewable_percentage": 14.1900054915}, {"Entity": "Thailand", "Year": 2019, "renewable_percentage": 14.7001731284}, {"Entity": "Thailand", "Year": 2020, "renewable_percentage": 13.7963737796}, {"Entity": "Ukraine", "Year": 2000, "renewable_percentage": 6.5860921352}, {"Entity": "Ukraine", "Year": 2001, "renewable_percentage": 6.9729761009}, {"Entity": "Ukraine", "Year": 2002, "renewable_percentage": 5.5597165409}, {"Entity": "Ukraine", "Year": 2003, "renewable_percentage": 5.1442841287}, {"Entity": "Ukraine", "Year": 2004, "renewable_percentage": 6.4718162839}, {"Entity": "Ukraine", "Year": 2005, "renewable_percentage": 6.6698940347}, {"Entity": "Ukraine", "Year": 2006, "renewable_percentage": 6.68633235}, {"Entity": "Ukraine", "Year": 2007, "renewable_percentage": 5.3380238605}, {"Entity": "Ukraine", "Year": 2008, "renewable_percentage": 6.1377090041}, {"Entity": "Ukraine", "Year": 2009, "renewable_percentage": 6.980762585}, {"Entity": "Ukraine", "Year": 2010, "renewable_percentage": 7.0914098083}, {"Entity": "Ukraine", "Year": 2011, "renewable_percentage": 5.7450628366}, {"Entity": "Ukraine", "Year": 2012, "renewable_percentage": 5.6614236741}, {"Entity": "Ukraine", "Year": 2013, "renewable_percentage": 7.8003200661}, {"Entity": "Ukraine", "Year": 2014, "renewable_percentage": 5.5885262117}, {"Entity": "Ukraine", "Year": 2015, "renewable_percentage": 4.3924771096}, {"Entity": "Ukraine", "Year": 2016, "renewable_percentage": 5.6797249171}, {"Entity": "Ukraine", "Year": 2017, "renewable_percentage": 7.0457194664}, {"Entity": "Ukraine", "Year": 2018, "renewable_percentage": 8.228528092}, {"Entity": "Ukraine", "Year": 2019, "renewable_percentage": 7.7754487096}, {"Entity": "Ukraine", "Year": 2020, "renewable_percentage": 11.8440577364}, {"Entity": "United Kingdom", "Year": 2000, "renewable_percentage": 2.6657406913}, {"Entity": "United Kingdom", "Year": 2001, "renewable_percentage": 2.5001961451}, {"Entity": "United Kingdom", "Year": 2002, "renewable_percentage": 2.8939157566}, {"Entity": "United Kingdom", "Year": 2003, "renewable_percentage": 2.6854802003}, {"Entity": "United Kingdom", "Year": 2004, "renewable_percentage": 3.6136880575}, {"Entity": "United Kingdom", "Year": 2005, "renewable_percentage": 4.2815234434}, {"Entity": "United Kingdom", "Year": 2006, "renewable_percentage": 4.6029890199}, {"Entity": "United Kingdom", "Year": 2007, "renewable_percentage": 5.0104331009}, {"Entity": "United Kingdom", "Year": 2008, "renewable_percentage": 5.6776842324}, {"Entity": "United Kingdom", "Year": 2009, "renewable_percentage": 6.7679854187}, {"Entity": "United Kingdom", "Year": 2010, "renewable_percentage": 6.9092924441}, {"Entity": "United Kingdom", "Year": 2011, "renewable_percentage": 9.6422505889}, {"Entity": "United Kingdom", "Year": 2012, "renewable_percentage": 11.4273047189}, {"Entity": "United Kingdom", "Year": 2013, "renewable_percentage": 14.9727052732}, {"Entity": "United Kingdom", "Year": 2014, "renewable_percentage": 19.2476358104}, {"Entity": "United Kingdom", "Year": 2015, "renewable_percentage": 24.6227709191}, {"Entity": "United Kingdom", "Year": 2016, "renewable_percentage": 24.6788390627}, {"Entity": "United Kingdom", "Year": 2017, "renewable_percentage": 29.4986571173}, {"Entity": "United Kingdom", "Year": 2018, "renewable_percentage": 33.2919818457}, {"Entity": "United Kingdom", "Year": 2019, "renewable_percentage": 37.4568630499}, {"Entity": "United Kingdom", "Year": 2020, "renewable_percentage": 42.8603962651}, {"Entity": "United States", "Year": 2000, "renewable_percentage": 9.2298992662}, {"Entity": "United States", "Year": 2001, "renewable_percentage": 7.5132056541}, {"Entity": "United States", "Year": 2002, "renewable_percentage": 8.749216358}, {"Entity": "United States", "Year": 2003, "renewable_percentage": 9.0252110397}, {"Entity": "United States", "Year": 2004, "renewable_percentage": 8.7334100887}, {"Entity": "United States", "Year": 2005, "renewable_percentage": 8.7494640631}, {"Entity": "United States", "Year": 2006, "renewable_percentage": 9.4184742052}, {"Entity": "United States", "Year": 2007, "renewable_percentage": 8.3984096829}, {"Entity": "United States", "Year": 2008, "renewable_percentage": 9.180943292}, {"Entity": "United States", "Year": 2009, "renewable_percentage": 10.547689996}, {"Entity": "United States", "Year": 2010, "renewable_percentage": 10.3180892283}, {"Entity": "United States", "Year": 2011, "renewable_percentage": 12.4665249812}, {"Entity": "United States", "Year": 2012, "renewable_percentage": 12.1841179804}, {"Entity": "United States", "Year": 2013, "renewable_percentage": 12.8311154179}, {"Entity": "United States", "Year": 2014, "renewable_percentage": 13.3503092033}, {"Entity": "United States", "Year": 2015, "renewable_percentage": 13.6261352256}, {"Entity": "United States", "Year": 2016, "renewable_percentage": 15.2880936304}, {"Entity": "United States", "Year": 2017, "renewable_percentage": 17.4515276472}, {"Entity": "United States", "Year": 2018, "renewable_percentage": 17.4499886946}, {"Entity": "United States", "Year": 2019, "renewable_percentage": 18.2946243489}, {"Entity": "United States", "Year": 2020, "renewable_percentage": 20.3156921037}], "metadata": {"Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}, "renewable_percentage": {"type": "number", "semanticType": "Percentage"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage']].copy()\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 158029.9988, 190729.9957, 209229.9957, ..., 6993180.176, 9861099.609, 9874660.156, 10096009.77\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 90.14, 91.79, 92.54, 804.95\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Transform the data into a long format where different energy sources (fossil fuels, nuclear, renewables) are unpivoted into separate rows. Each row should contain the year, entity (country), energy source type, and the corresponding energy value in TWh. This will enable visualization of energy generation trends over time by source and country.\",\n \"display_instruction\": \"Show **energy generation** trends by **source** and **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"source\", \"energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n },\n \"reason\": \"The user wants to visualize energy data across different sources with a line chart faceted by source. The original data has energy sources in separate columns (fossil fuels, nuclear, renewables), so we need to unpivot these columns into a long format with 'source' and 'energy' fields. The chart_encodings provided by the user are appropriate for this visualization goal, using faceting (column) to separate different energy sources.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Year energy source\n0 Australia 2000 181.05 fossil fuels\n1 Australia 2001 194.33 fossil fuels\n2 Australia 2002 197.29 fossil fuels\n3 Australia 2003 195.13 fossil fuels\n4 Australia 2004 203.66 fossil fuels\n5 Australia 2005 195.95 fossil fuels\n6 Australia 2006 198.72 fossil fuels\n7 Australia 2007 208.59 fossil fuels\n8 Australia 2008 211.06 fossil fuels\n9 Australia 2009 216.42 fossil fuels\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show renewable percentage for each country\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage for each country and year. The renewable percentage is computed as the ratio of renewable energy to total energy (sum of fossil fuels, nuclear, and renewables) multiplied by 100. The output should contain year, entity (country), and the renewable percentage value.\",\n \"display_instruction\": \"Show **renewable percentage** for each **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"renewable_percentage\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"renewable_percentage\",\n \"color\": \"Entity\"\n },\n \"reason\": \"The user wants to see renewable percentage trends, which requires calculating the proportion of renewable energy relative to total energy generation. This is a single metric per country per year, so we don't need the 'column' faceting by source anymore. The chart_encodings are updated to reflect that we're now showing a percentage metric rather than absolute energy values by source.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage']].copy()\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-82", "resultTableId": "table-45", "chart": {"id": "chart-1760738416626", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-1760738385163"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {"fieldID": "concept-1760738389404", "sortBy": "[\"fossil fuels\",\"nuclear\",\"renewables\"]"}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-82", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "show renewable percentage for each country", "displayContent": "Show **renewable percentage** for each **Entity** over **Year**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code transforms global energy data to analyze renewable energy adoption:\n\n- Calculates **total_energy** by summing electricity generation from three sources: **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n- Computes **renewable_percentage** by dividing **Electricity from renewables (TWh)** by **total_energy** and multiplying by **100**\n- Handles edge cases by replacing infinite values (from division by zero) with **NaN**\n- Filters the dataset to retain only **Year**, **Entity** (country), and **renewable_percentage** columns", "concepts": [{"explanation": "The proportion of a country's total electricity generation that comes from renewable sources, expressed as a percentage. Calculated as: \\( \\frac{\\text{Electricity from renewables}}{\\text{Total electricity generation}} \\times 100 \\). This metric indicates the degree of renewable energy adoption in each country's energy mix.", "field": "renewable_percentage"}], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5738290.039, 9861099.609, 10502929.69, 10707219.73\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., nan, nan, nan, nan\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage']].copy()\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code transforms global energy data to analyze renewable energy adoption:\n\n- Calculates **total_energy** by summing electricity generation from three sources: **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n- Computes **renewable_percentage** by dividing **Electricity from renewables (TWh)** by **total_energy** and multiplying by **100**\n- Handles edge cases by replacing infinite values (from division by zero) with **NaN**\n- Filters the dataset to retain only **Year**, **Entity** (country), and **renewable_percentage** columns\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"renewable_percentage\",\n \"explanation\": \"The proportion of a country's total electricity generation that comes from renewable sources, expressed as a percentage. Calculated as: \\\\( \\\\frac{\\\\text{Electricity from renewables}}{\\\\text{Total electricity generation}} \\\\times 100 \\\\). This metric indicates the degree of renewable energy adoption in each country's energy mix.\"\n }\n]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-78", "displayId": "renewable-energy-rank", "names": ["Entity", "Year", "rank", "renewable_percentage"], "rows": [{"Entity": "Australia", "Year": 2000, "rank": 11, "renewable_percentage": 8.6344368187}, {"Entity": "Australia", "Year": 2001, "rank": 10, "renewable_percentage": 8.2180135078}, {"Entity": "Australia", "Year": 2002, "rank": 11, "renewable_percentage": 8.0833022736}, {"Entity": "Australia", "Year": 2003, "rank": 11, "renewable_percentage": 8.6598324205}, {"Entity": "Australia", "Year": 2004, "rank": 12, "renewable_percentage": 8.7013045232}, {"Entity": "Australia", "Year": 2005, "rank": 11, "renewable_percentage": 9.1562355123}, {"Entity": "Australia", "Year": 2006, "rank": 11, "renewable_percentage": 9.6357600837}, {"Entity": "Australia", "Year": 2007, "rank": 11, "renewable_percentage": 9.1190310213}, {"Entity": "Australia", "Year": 2008, "rank": 12, "renewable_percentage": 8.0548900022}, {"Entity": "Australia", "Year": 2009, "rank": 12, "renewable_percentage": 7.8043793133}, {"Entity": "Australia", "Year": 2010, "rank": 12, "renewable_percentage": 9.0442152121}, {"Entity": "Australia", "Year": 2011, "rank": 11, "renewable_percentage": 11.3454273735}, {"Entity": "Australia", "Year": 2012, "rank": 12, "renewable_percentage": 11.4105750279}, {"Entity": "Australia", "Year": 2013, "rank": 11, "renewable_percentage": 14.8708583355}, {"Entity": "Australia", "Year": 2014, "rank": 11, "renewable_percentage": 14.9621290509}, {"Entity": "Australia", "Year": 2015, "rank": 12, "renewable_percentage": 14.3476000693}, {"Entity": "Australia", "Year": 2016, "rank": 11, "renewable_percentage": 15.6093794449}, {"Entity": "Australia", "Year": 2017, "rank": 12, "renewable_percentage": 16.3138729943}, {"Entity": "Australia", "Year": 2018, "rank": 12, "renewable_percentage": 17.145938174}, {"Entity": "Australia", "Year": 2019, "rank": 8, "renewable_percentage": 21.3759705435}, {"Entity": "Australia", "Year": 2020, "rank": 8, "renewable_percentage": 25.5031684668}, {"Entity": "Brazil", "Year": 2000, "rank": 1, "renewable_percentage": 90.1307723743}, {"Entity": "Brazil", "Year": 2001, "rank": 1, "renewable_percentage": 84.6953615744}, {"Entity": "Brazil", "Year": 2002, "rank": 1, "renewable_percentage": 86.0883364189}, {"Entity": "Brazil", "Year": 2003, "rank": 1, "renewable_percentage": 87.4561159097}, {"Entity": "Brazil", "Year": 2004, "rank": 1, "renewable_percentage": 86.4260041451}, {"Entity": "Brazil", "Year": 2005, "rank": 1, "renewable_percentage": 87.6781562721}, {"Entity": "Brazil", "Year": 2006, "rank": 1, "renewable_percentage": 87.2842473236}, {"Entity": "Brazil", "Year": 2007, "rank": 1, "renewable_percentage": 88.7252098726}, {"Entity": "Brazil", "Year": 2008, "rank": 1, "renewable_percentage": 84.8072313004}, {"Entity": "Brazil", "Year": 2009, "rank": 1, "renewable_percentage": 89.4172280725}, {"Entity": "Brazil", "Year": 2010, "rank": 1, "renewable_percentage": 85.3576882415}, {"Entity": "Brazil", "Year": 2011, "rank": 1, "renewable_percentage": 87.6618820986}, {"Entity": "Brazil", "Year": 2012, "rank": 1, "renewable_percentage": 83.1164558813}, {"Entity": "Brazil", "Year": 2013, "rank": 1, "renewable_percentage": 77.5240022006}, {"Entity": "Brazil", "Year": 2014, "rank": 1, "renewable_percentage": 74.0418657409}, {"Entity": "Brazil", "Year": 2015, "rank": 1, "renewable_percentage": 75.0231817625}, {"Entity": "Brazil", "Year": 2016, "rank": 1, "renewable_percentage": 81.0938046902}, {"Entity": "Brazil", "Year": 2017, "rank": 1, "renewable_percentage": 79.9091472228}, {"Entity": "Brazil", "Year": 2018, "rank": 1, "renewable_percentage": 82.9198505403}, {"Entity": "Brazil", "Year": 2019, "rank": 1, "renewable_percentage": 82.8548799017}, {"Entity": "Brazil", "Year": 2020, "rank": 1, "renewable_percentage": 84.6411771408}, {"Entity": "Canada", "Year": 2000, "rank": 2, "renewable_percentage": 61.8095917882}, {"Entity": "Canada", "Year": 2001, "rank": 2, "renewable_percentage": 59.3287558747}, {"Entity": "Canada", "Year": 2002, "rank": 2, "renewable_percentage": 61.1477403113}, {"Entity": "Canada", "Year": 2003, "rank": 2, "renewable_percentage": 60.0789685174}, {"Entity": "Canada", "Year": 2004, "rank": 2, "renewable_percentage": 59.6967771845}, {"Entity": "Canada", "Year": 2005, "rank": 2, "renewable_percentage": 60.8208155391}, {"Entity": "Canada", "Year": 2006, "rank": 2, "renewable_percentage": 60.8271602855}, {"Entity": "Canada", "Year": 2007, "rank": 2, "renewable_percentage": 61.2460642446}, {"Entity": "Canada", "Year": 2008, "rank": 2, "renewable_percentage": 62.6520720838}, {"Entity": "Canada", "Year": 2009, "rank": 2, "renewable_percentage": 63.8919227732}, {"Entity": "Canada", "Year": 2010, "rank": 2, "renewable_percentage": 62.9421470558}, {"Entity": "Canada", "Year": 2011, "rank": 2, "renewable_percentage": 64.0922915917}, {"Entity": "Canada", "Year": 2012, "rank": 2, "renewable_percentage": 65.098730952}, {"Entity": "Canada", "Year": 2013, "rank": 2, "renewable_percentage": 65.4320794066}, {"Entity": "Canada", "Year": 2014, "rank": 2, "renewable_percentage": 64.791145907}, {"Entity": "Canada", "Year": 2015, "rank": 2, "renewable_percentage": 65.2946239925}, {"Entity": "Canada", "Year": 2016, "rank": 2, "renewable_percentage": 66.1890584295}, {"Entity": "Canada", "Year": 2017, "rank": 2, "renewable_percentage": 67.5399410579}, {"Entity": "Canada", "Year": 2018, "rank": 2, "renewable_percentage": 67.3685700357}, {"Entity": "Canada", "Year": 2019, "rank": 2, "renewable_percentage": 67.1741623137}, {"Entity": "Canada", "Year": 2020, "rank": 2, "renewable_percentage": 68.7796436354}, {"Entity": "China", "Year": 2000, "rank": 5, "renewable_percentage": 16.639126586}, {"Entity": "China", "Year": 2001, "rank": 6, "renewable_percentage": 18.9581237042}, {"Entity": "China", "Year": 2002, "rank": 3, "renewable_percentage": 17.6185006046}, {"Entity": "China", "Year": 2003, "rank": 6, "renewable_percentage": 15.0362717081}, {"Entity": "China", "Year": 2004, "rank": 6, "renewable_percentage": 16.2224108273}, {"Entity": "China", "Year": 2005, "rank": 5, "renewable_percentage": 16.1731179957}, {"Entity": "China", "Year": 2006, "rank": 7, "renewable_percentage": 15.5884036124}, {"Entity": "China", "Year": 2007, "rank": 7, "renewable_percentage": 15.2583847828}, {"Entity": "China", "Year": 2008, "rank": 5, "renewable_percentage": 19.0253335469}, {"Entity": "China", "Year": 2009, "rank": 5, "renewable_percentage": 17.8857170547}, {"Entity": "China", "Year": 2010, "rank": 6, "renewable_percentage": 18.7800759915}, {"Entity": "China", "Year": 2011, "rank": 7, "renewable_percentage": 16.8902341543}, {"Entity": "China", "Year": 2012, "rank": 6, "renewable_percentage": 20.122965176}, {"Entity": "China", "Year": 2013, "rank": 6, "renewable_percentage": 20.2152481955}, {"Entity": "China", "Year": 2014, "rank": 6, "renewable_percentage": 22.3502204285}, {"Entity": "China", "Year": 2015, "rank": 7, "renewable_percentage": 24.079270189}, {"Entity": "China", "Year": 2016, "rank": 6, "renewable_percentage": 25.0007798429}, {"Entity": "China", "Year": 2017, "rank": 7, "renewable_percentage": 25.419242299}, {"Entity": "China", "Year": 2018, "rank": 7, "renewable_percentage": 25.7747942589}, {"Entity": "China", "Year": 2019, "rank": 7, "renewable_percentage": 26.9995671106}, {"Entity": "China", "Year": 2020, "rank": 7, "renewable_percentage": 28.2464606924}, {"Entity": "France", "Year": 2000, "rank": 8, "renewable_percentage": 12.7117691154}, {"Entity": "France", "Year": 2001, "rank": 7, "renewable_percentage": 13.9961372206}, {"Entity": "France", "Year": 2002, "rank": 8, "renewable_percentage": 11.3544157067}, {"Entity": "France", "Year": 2003, "rank": 9, "renewable_percentage": 10.9783540506}, {"Entity": "France", "Year": 2004, "rank": 9, "renewable_percentage": 11.0051305559}, {"Entity": "France", "Year": 2005, "rank": 10, "renewable_percentage": 9.6479837153}, {"Entity": "France", "Year": 2006, "rank": 10, "renewable_percentage": 10.7235915493}, {"Entity": "France", "Year": 2007, "rank": 9, "renewable_percentage": 11.4370075239}, {"Entity": "France", "Year": 2008, "rank": 9, "renewable_percentage": 12.7487441615}, {"Entity": "France", "Year": 2009, "rank": 9, "renewable_percentage": 12.8776856068}, {"Entity": "France", "Year": 2010, "rank": 9, "renewable_percentage": 13.6240072491}, {"Entity": "France", "Year": 2011, "rank": 10, "renewable_percentage": 11.63553049}, {"Entity": "France", "Year": 2012, "rank": 9, "renewable_percentage": 15.0331522889}, {"Entity": "France", "Year": 2013, "rank": 7, "renewable_percentage": 17.2469424928}, {"Entity": "France", "Year": 2014, "rank": 9, "renewable_percentage": 16.6074992494}, {"Entity": "France", "Year": 2015, "rank": 9, "renewable_percentage": 16.002230276}, {"Entity": "France", "Year": 2016, "rank": 8, "renewable_percentage": 17.7212924013}, {"Entity": "France", "Year": 2017, "rank": 11, "renewable_percentage": 16.6576751547}, {"Entity": "France", "Year": 2018, "rank": 8, "renewable_percentage": 19.7315179827}, {"Entity": "France", "Year": 2019, "rank": 9, "renewable_percentage": 20.0116665488}, {"Entity": "France", "Year": 2020, "rank": 9, "renewable_percentage": 23.7610241821}, {"Entity": "Germany", "Year": 2000, "rank": 14, "renewable_percentage": 6.1977983575}, {"Entity": "Germany", "Year": 2001, "rank": 14, "renewable_percentage": 6.5132585197}, {"Entity": "Germany", "Year": 2002, "rank": 13, "renewable_percentage": 7.6431369854}, {"Entity": "Germany", "Year": 2003, "rank": 12, "renewable_percentage": 7.7455438643}, {"Entity": "Germany", "Year": 2004, "rank": 10, "renewable_percentage": 9.4989185292}, {"Entity": "Germany", "Year": 2005, "rank": 8, "renewable_percentage": 10.3356645637}, {"Entity": "Germany", "Year": 2006, "rank": 8, "renewable_percentage": 11.5129959829}, {"Entity": "Germany", "Year": 2007, "rank": 8, "renewable_percentage": 14.135471525}, {"Entity": "Germany", "Year": 2008, "rank": 8, "renewable_percentage": 14.8894504106}, {"Entity": "Germany", "Year": 2009, "rank": 7, "renewable_percentage": 16.2902842395}, {"Entity": "Germany", "Year": 2010, "rank": 7, "renewable_percentage": 16.8384989754}, {"Entity": "Germany", "Year": 2011, "rank": 5, "renewable_percentage": 20.4967199299}, {"Entity": "Germany", "Year": 2012, "rank": 5, "renewable_percentage": 23.056464482}, {"Entity": "Germany", "Year": 2013, "rank": 5, "renewable_percentage": 24.1368929731}, {"Entity": "Germany", "Year": 2014, "rank": 5, "renewable_percentage": 26.2182434067}, {"Entity": "Germany", "Year": 2015, "rank": 5, "renewable_percentage": 29.4721888318}, {"Entity": "Germany", "Year": 2016, "rank": 5, "renewable_percentage": 29.4990435013}, {"Entity": "Germany", "Year": 2017, "rank": 4, "renewable_percentage": 33.4855497593}, {"Entity": "Germany", "Year": 2018, "rank": 5, "renewable_percentage": 35.0976735365}, {"Entity": "Germany", "Year": 2019, "rank": 3, "renewable_percentage": 40.0890757144}, {"Entity": "Germany", "Year": 2020, "rank": 3, "renewable_percentage": 44.3324048937}, {"Entity": "India", "Year": 2000, "rank": 7, "renewable_percentage": 14.0481982534}, {"Entity": "India", "Year": 2001, "rank": 8, "renewable_percentage": 12.9997099422}, {"Entity": "India", "Year": 2002, "rank": 7, "renewable_percentage": 11.938193032}, {"Entity": "India", "Year": 2003, "rank": 8, "renewable_percentage": 11.695109147}, {"Entity": "India", "Year": 2004, "rank": 7, "renewable_percentage": 15.6375300722}, {"Entity": "India", "Year": 2005, "rank": 6, "renewable_percentage": 15.2543575768}, {"Entity": "India", "Year": 2006, "rank": 5, "renewable_percentage": 17.1352578483}, {"Entity": "India", "Year": 2007, "rank": 4, "renewable_percentage": 17.8019742295}, {"Entity": "India", "Year": 2008, "rank": 7, "renewable_percentage": 16.768266921}, {"Entity": "India", "Year": 2009, "rank": 8, "renewable_percentage": 15.269804822}, {"Entity": "India", "Year": 2010, "rank": 8, "renewable_percentage": 15.2122201244}, {"Entity": "India", "Year": 2011, "rank": 8, "renewable_percentage": 16.7911025145}, {"Entity": "India", "Year": 2012, "rank": 8, "renewable_percentage": 15.1350014654}, {"Entity": "India", "Year": 2013, "rank": 8, "renewable_percentage": 16.3941577818}, {"Entity": "India", "Year": 2014, "rank": 10, "renewable_percentage": 16.0092550039}, {"Entity": "India", "Year": 2015, "rank": 11, "renewable_percentage": 15.3718720687}, {"Entity": "India", "Year": 2016, "rank": 13, "renewable_percentage": 14.8548475703}, {"Entity": "India", "Year": 2017, "rank": 13, "renewable_percentage": 15.9669920335}, {"Entity": "India", "Year": 2018, "rank": 13, "renewable_percentage": 16.6949549709}, {"Entity": "India", "Year": 2019, "rank": 11, "renewable_percentage": 18.6915426873}, {"Entity": "India", "Year": 2020, "rank": 13, "renewable_percentage": 20.2059243238}, {"Entity": "Indonesia", "Year": 2000, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2001, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2002, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2003, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2004, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2005, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2006, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2007, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2008, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2009, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2010, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2011, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2012, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2013, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2014, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2015, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2016, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2017, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2018, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2019, "rank": null, "renewable_percentage": null}, {"Entity": "Indonesia", "Year": 2020, "rank": null, "renewable_percentage": null}, {"Entity": "Italy", "Year": 2000, "rank": 4, "renewable_percentage": 18.900241501}, {"Entity": "Italy", "Year": 2001, "rank": 4, "renewable_percentage": 20.049431902}, {"Entity": "Italy", "Year": 2002, "rank": 4, "renewable_percentage": 17.4555571614}, {"Entity": "Italy", "Year": 2003, "rank": 4, "renewable_percentage": 16.4202116476}, {"Entity": "Italy", "Year": 2004, "rank": 4, "renewable_percentage": 18.2749380999}, {"Entity": "Italy", "Year": 2005, "rank": 4, "renewable_percentage": 16.3769782226}, {"Entity": "Italy", "Year": 2006, "rank": 6, "renewable_percentage": 16.5128639906}, {"Entity": "Italy", "Year": 2007, "rank": 6, "renewable_percentage": 15.5333485238}, {"Entity": "Italy", "Year": 2008, "rank": 6, "renewable_percentage": 18.6112}, {"Entity": "Italy", "Year": 2009, "rank": 4, "renewable_percentage": 24.0837332221}, {"Entity": "Italy", "Year": 2010, "rank": 4, "renewable_percentage": 25.8400187976}, {"Entity": "Italy", "Year": 2011, "rank": 4, "renewable_percentage": 27.6773203443}, {"Entity": "Italy", "Year": 2012, "rank": 3, "renewable_percentage": 31.1049649217}, {"Entity": "Italy", "Year": 2013, "rank": 4, "renewable_percentage": 39.0148744209}, {"Entity": "Italy", "Year": 2014, "rank": 3, "renewable_percentage": 43.4976931949}, {"Entity": "Italy", "Year": 2015, "rank": 3, "renewable_percentage": 38.7577860829}, {"Entity": "Italy", "Year": 2016, "rank": 4, "renewable_percentage": 37.6079387187}, {"Entity": "Italy", "Year": 2017, "rank": 3, "renewable_percentage": 35.4174479255}, {"Entity": "Italy", "Year": 2018, "rank": 3, "renewable_percentage": 39.8100142663}, {"Entity": "Italy", "Year": 2019, "rank": 4, "renewable_percentage": 39.7563068474}, {"Entity": "Italy", "Year": 2020, "rank": 6, "renewable_percentage": 42.0397741576}, {"Entity": "Japan", "Year": 2000, "rank": 9, "renewable_percentage": 10.5382436261}, {"Entity": "Japan", "Year": 2001, "rank": 9, "renewable_percentage": 10.447653504}, {"Entity": "Japan", "Year": 2002, "rank": 9, "renewable_percentage": 10.2477294843}, {"Entity": "Japan", "Year": 2003, "rank": 7, "renewable_percentage": 11.6993698448}, {"Entity": "Japan", "Year": 2004, "rank": 8, "renewable_percentage": 11.4198974767}, {"Entity": "Japan", "Year": 2005, "rank": 9, "renewable_percentage": 9.9068127192}, {"Entity": "Japan", "Year": 2006, "rank": 9, "renewable_percentage": 10.8554989442}, {"Entity": "Japan", "Year": 2007, "rank": 10, "renewable_percentage": 9.3897588285}, {"Entity": "Japan", "Year": 2008, "rank": 10, "renewable_percentage": 10.0196834738}, {"Entity": "Japan", "Year": 2009, "rank": 11, "renewable_percentage": 10.4667464874}, {"Entity": "Japan", "Year": 2010, "rank": 10, "renewable_percentage": 10.5269966826}, {"Entity": "Japan", "Year": 2011, "rank": 12, "renewable_percentage": 11.1272421632}, {"Entity": "Japan", "Year": 2012, "rank": 13, "renewable_percentage": 10.6143703421}, {"Entity": "Japan", "Year": 2013, "rank": 13, "renewable_percentage": 11.7965798852}, {"Entity": "Japan", "Year": 2014, "rank": 13, "renewable_percentage": 13.2719619718}, {"Entity": "Japan", "Year": 2015, "rank": 10, "renewable_percentage": 15.6586817408}, {"Entity": "Japan", "Year": 2016, "rank": 10, "renewable_percentage": 15.6920107068}, {"Entity": "Japan", "Year": 2017, "rank": 10, "renewable_percentage": 17.3559698312}, {"Entity": "Japan", "Year": 2018, "rank": 9, "renewable_percentage": 18.144181175}, {"Entity": "Japan", "Year": 2019, "rank": 10, "renewable_percentage": 19.4223288251}, {"Entity": "Japan", "Year": 2020, "rank": 10, "renewable_percentage": 21.324925062}, {"Entity": "Kazakhstan", "Year": 2000, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2001, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2002, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2003, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2004, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2005, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2006, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2007, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2008, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2009, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2010, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2011, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2012, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2013, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2014, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2015, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2016, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2017, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2018, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2019, "rank": null, "renewable_percentage": null}, {"Entity": "Kazakhstan", "Year": 2020, "rank": null, "renewable_percentage": null}, {"Entity": "Mexico", "Year": 2000, "rank": 3, "renewable_percentage": 22.9291160107}, {"Entity": "Mexico", "Year": 2001, "rank": 5, "renewable_percentage": 19.6649599841}, {"Entity": "Mexico", "Year": 2002, "rank": 5, "renewable_percentage": 17.4220963173}, {"Entity": "Mexico", "Year": 2003, "rank": 5, "renewable_percentage": 15.8536585366}, {"Entity": "Mexico", "Year": 2004, "rank": 5, "renewable_percentage": 17.3134463687}, {"Entity": "Mexico", "Year": 2005, "rank": 3, "renewable_percentage": 18.2780827246}, {"Entity": "Mexico", "Year": 2006, "rank": 3, "renewable_percentage": 18.4256091896}, {"Entity": "Mexico", "Year": 2007, "rank": 5, "renewable_percentage": 17.2761561168}, {"Entity": "Mexico", "Year": 2008, "rank": 3, "renewable_percentage": 21.5387105913}, {"Entity": "Mexico", "Year": 2009, "rank": 6, "renewable_percentage": 16.5369729069}, {"Entity": "Mexico", "Year": 2010, "rank": 5, "renewable_percentage": 19.4281608109}, {"Entity": "Mexico", "Year": 2011, "rank": 6, "renewable_percentage": 18.0916357408}, {"Entity": "Mexico", "Year": 2012, "rank": 7, "renewable_percentage": 16.5759438104}, {"Entity": "Mexico", "Year": 2013, "rank": 9, "renewable_percentage": 15.5492898914}, {"Entity": "Mexico", "Year": 2014, "rank": 7, "renewable_percentage": 19.8008201523}, {"Entity": "Mexico", "Year": 2015, "rank": 8, "renewable_percentage": 17.5976903451}, {"Entity": "Mexico", "Year": 2016, "rank": 9, "renewable_percentage": 17.4806943436}, {"Entity": "Mexico", "Year": 2017, "rank": 8, "renewable_percentage": 18.0759526428}, {"Entity": "Mexico", "Year": 2018, "rank": 10, "renewable_percentage": 17.703752786}, {"Entity": "Mexico", "Year": 2019, "rank": 12, "renewable_percentage": 18.5487927565}, {"Entity": "Mexico", "Year": 2020, "rank": 11, "renewable_percentage": 21.2552224134}, {"Entity": "Poland", "Year": 2000, "rank": 16, "renewable_percentage": 1.6273222517}, {"Entity": "Poland", "Year": 2001, "rank": 16, "renewable_percentage": 1.934316727}, {"Entity": "Poland", "Year": 2002, "rank": 16, "renewable_percentage": 1.9439960699}, {"Entity": "Poland", "Year": 2003, "rank": 16, "renewable_percentage": 1.4999000067}, {"Entity": "Poland", "Year": 2004, "rank": 16, "renewable_percentage": 2.1016681991}, {"Entity": "Poland", "Year": 2005, "rank": 16, "renewable_percentage": 2.4830699774}, {"Entity": "Poland", "Year": 2006, "rank": 16, "renewable_percentage": 2.673730134}, {"Entity": "Poland", "Year": 2007, "rank": 16, "renewable_percentage": 3.4256513785}, {"Entity": "Poland", "Year": 2008, "rank": 16, "renewable_percentage": 4.2744438696}, {"Entity": "Poland", "Year": 2009, "rank": 16, "renewable_percentage": 5.7515388179}, {"Entity": "Poland", "Year": 2010, "rank": 14, "renewable_percentage": 6.9299363057}, {"Entity": "Poland", "Year": 2011, "rank": 14, "renewable_percentage": 8.0547205693}, {"Entity": "Poland", "Year": 2012, "rank": 14, "renewable_percentage": 10.4436057663}, {"Entity": "Poland", "Year": 2013, "rank": 14, "renewable_percentage": 10.4081508145}, {"Entity": "Poland", "Year": 2014, "rank": 14, "renewable_percentage": 12.5331481248}, {"Entity": "Poland", "Year": 2015, "rank": 13, "renewable_percentage": 13.8151485631}, {"Entity": "Poland", "Year": 2016, "rank": 14, "renewable_percentage": 13.7335179722}, {"Entity": "Poland", "Year": 2017, "rank": 14, "renewable_percentage": 14.1999646913}, {"Entity": "Poland", "Year": 2018, "rank": 15, "renewable_percentage": 12.7559148032}, {"Entity": "Poland", "Year": 2019, "rank": 14, "renewable_percentage": 15.6157998037}, {"Entity": "Poland", "Year": 2020, "rank": 14, "renewable_percentage": 17.9648720886}, {"Entity": "Saudi Arabia", "Year": 2000, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2001, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2002, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2003, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2004, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2005, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2006, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2007, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2008, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2009, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2010, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2011, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2012, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2013, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2014, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2015, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2016, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2017, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2018, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2019, "rank": null, "renewable_percentage": null}, {"Entity": "Saudi Arabia", "Year": 2020, "rank": null, "renewable_percentage": null}, {"Entity": "South Africa", "Year": 2000, "rank": 17, "renewable_percentage": 0.9110805721}, {"Entity": "South Africa", "Year": 2001, "rank": 17, "renewable_percentage": 1.2516536074}, {"Entity": "South Africa", "Year": 2002, "rank": 17, "renewable_percentage": 1.3802249619}, {"Entity": "South Africa", "Year": 2003, "rank": 17, "renewable_percentage": 0.545271261}, {"Entity": "South Africa", "Year": 2004, "rank": 17, "renewable_percentage": 0.5827199439}, {"Entity": "South Africa", "Year": 2005, "rank": 17, "renewable_percentage": 0.763458686}, {"Entity": "South Africa", "Year": 2006, "rank": 17, "renewable_percentage": 1.3863060017}, {"Entity": "South Africa", "Year": 2007, "rank": 17, "renewable_percentage": 0.5267209594}, {"Entity": "South Africa", "Year": 2008, "rank": 17, "renewable_percentage": 0.6895692269}, {"Entity": "South Africa", "Year": 2009, "rank": 17, "renewable_percentage": 0.8031088083}, {"Entity": "South Africa", "Year": 2010, "rank": 17, "renewable_percentage": 1.0330068318}, {"Entity": "South Africa", "Year": 2011, "rank": 17, "renewable_percentage": 1.0184465622}, {"Entity": "South Africa", "Year": 2012, "rank": 17, "renewable_percentage": 0.6890826069}, {"Entity": "South Africa", "Year": 2013, "rank": 17, "renewable_percentage": 0.6792168043}, {"Entity": "South Africa", "Year": 2014, "rank": 17, "renewable_percentage": 1.4288129861}, {"Entity": "South Africa", "Year": 2015, "rank": 17, "renewable_percentage": 2.6256790549}, {"Entity": "South Africa", "Year": 2016, "rank": 17, "renewable_percentage": 3.2586126531}, {"Entity": "South Africa", "Year": 2017, "rank": 17, "renewable_percentage": 4.2202606137}, {"Entity": "South Africa", "Year": 2018, "rank": 17, "renewable_percentage": 5.1554655529}, {"Entity": "South Africa", "Year": 2019, "rank": 17, "renewable_percentage": 5.3589699864}, {"Entity": "South Africa", "Year": 2020, "rank": 17, "renewable_percentage": 5.780581212}, {"Entity": "Spain", "Year": 2000, "rank": 6, "renewable_percentage": 15.6119862394}, {"Entity": "Spain", "Year": 2001, "rank": 3, "renewable_percentage": 21.1524434719}, {"Entity": "Spain", "Year": 2002, "rank": 6, "renewable_percentage": 13.8260180901}, {"Entity": "Spain", "Year": 2003, "rank": 3, "renewable_percentage": 21.667314419}, {"Entity": "Spain", "Year": 2004, "rank": 3, "renewable_percentage": 18.3190206468}, {"Entity": "Spain", "Year": 2005, "rank": 7, "renewable_percentage": 14.8597342333}, {"Entity": "Spain", "Year": 2006, "rank": 4, "renewable_percentage": 17.6623992413}, {"Entity": "Spain", "Year": 2007, "rank": 3, "renewable_percentage": 19.3347262296}, {"Entity": "Spain", "Year": 2008, "rank": 4, "renewable_percentage": 20.0051501593}, {"Entity": "Spain", "Year": 2009, "rank": 3, "renewable_percentage": 25.4107639008}, {"Entity": "Spain", "Year": 2010, "rank": 3, "renewable_percentage": 32.7922186819}, {"Entity": "Spain", "Year": 2011, "rank": 3, "renewable_percentage": 30.0408415417}, {"Entity": "Spain", "Year": 2012, "rank": 4, "renewable_percentage": 29.6047928652}, {"Entity": "Spain", "Year": 2013, "rank": 3, "renewable_percentage": 39.5850357054}, {"Entity": "Spain", "Year": 2014, "rank": 4, "renewable_percentage": 40.1032952644}, {"Entity": "Spain", "Year": 2015, "rank": 4, "renewable_percentage": 34.9899091826}, {"Entity": "Spain", "Year": 2016, "rank": 3, "renewable_percentage": 38.5818061138}, {"Entity": "Spain", "Year": 2017, "rank": 5, "renewable_percentage": 32.220593624}, {"Entity": "Spain", "Year": 2018, "rank": 4, "renewable_percentage": 38.2080329557}, {"Entity": "Spain", "Year": 2019, "rank": 6, "renewable_percentage": 37.280815091}, {"Entity": "Spain", "Year": 2020, "rank": 4, "renewable_percentage": 43.8108805298}, {"Entity": "Thailand", "Year": 2000, "rank": 12, "renewable_percentage": 7.1261029822}, {"Entity": "Thailand", "Year": 2001, "rank": 12, "renewable_percentage": 7.061527212}, {"Entity": "Thailand", "Year": 2002, "rank": 12, "renewable_percentage": 7.9444772593}, {"Entity": "Thailand", "Year": 2003, "rank": 13, "renewable_percentage": 7.6718362852}, {"Entity": "Thailand", "Year": 2004, "rank": 13, "renewable_percentage": 6.5163549406}, {"Entity": "Thailand", "Year": 2005, "rank": 14, "renewable_percentage": 6.0325203252}, {"Entity": "Thailand", "Year": 2006, "rank": 13, "renewable_percentage": 7.5988547551}, {"Entity": "Thailand", "Year": 2007, "rank": 13, "renewable_percentage": 7.7085852479}, {"Entity": "Thailand", "Year": 2008, "rank": 13, "renewable_percentage": 6.5625458278}, {"Entity": "Thailand", "Year": 2009, "rank": 15, "renewable_percentage": 6.6263303689}, {"Entity": "Thailand", "Year": 2010, "rank": 16, "renewable_percentage": 5.7085828343}, {"Entity": "Thailand", "Year": 2011, "rank": 15, "renewable_percentage": 8.039961941}, {"Entity": "Thailand", "Year": 2012, "rank": 15, "renewable_percentage": 8.5396118358}, {"Entity": "Thailand", "Year": 2013, "rank": 16, "renewable_percentage": 7.6765035487}, {"Entity": "Thailand", "Year": 2014, "rank": 15, "renewable_percentage": 8.395728489}, {"Entity": "Thailand", "Year": 2015, "rank": 15, "renewable_percentage": 7.9949619145}, {"Entity": "Thailand", "Year": 2016, "rank": 15, "renewable_percentage": 8.9840234023}, {"Entity": "Thailand", "Year": 2017, "rank": 15, "renewable_percentage": 10.9570957096}, {"Entity": "Thailand", "Year": 2018, "rank": 14, "renewable_percentage": 14.1900054915}, {"Entity": "Thailand", "Year": 2019, "rank": 15, "renewable_percentage": 14.7001731284}, {"Entity": "Thailand", "Year": 2020, "rank": 15, "renewable_percentage": 13.7963737796}, {"Entity": "Ukraine", "Year": 2000, "rank": 13, "renewable_percentage": 6.5860921352}, {"Entity": "Ukraine", "Year": 2001, "rank": 13, "renewable_percentage": 6.9729761009}, {"Entity": "Ukraine", "Year": 2002, "rank": 14, "renewable_percentage": 5.5597165409}, {"Entity": "Ukraine", "Year": 2003, "rank": 14, "renewable_percentage": 5.1442841287}, {"Entity": "Ukraine", "Year": 2004, "rank": 14, "renewable_percentage": 6.4718162839}, {"Entity": "Ukraine", "Year": 2005, "rank": 13, "renewable_percentage": 6.6698940347}, {"Entity": "Ukraine", "Year": 2006, "rank": 14, "renewable_percentage": 6.68633235}, {"Entity": "Ukraine", "Year": 2007, "rank": 14, "renewable_percentage": 5.3380238605}, {"Entity": "Ukraine", "Year": 2008, "rank": 14, "renewable_percentage": 6.1377090041}, {"Entity": "Ukraine", "Year": 2009, "rank": 13, "renewable_percentage": 6.980762585}, {"Entity": "Ukraine", "Year": 2010, "rank": 13, "renewable_percentage": 7.0914098083}, {"Entity": "Ukraine", "Year": 2011, "rank": 16, "renewable_percentage": 5.7450628366}, {"Entity": "Ukraine", "Year": 2012, "rank": 16, "renewable_percentage": 5.6614236741}, {"Entity": "Ukraine", "Year": 2013, "rank": 15, "renewable_percentage": 7.8003200661}, {"Entity": "Ukraine", "Year": 2014, "rank": 16, "renewable_percentage": 5.5885262117}, {"Entity": "Ukraine", "Year": 2015, "rank": 16, "renewable_percentage": 4.3924771096}, {"Entity": "Ukraine", "Year": 2016, "rank": 16, "renewable_percentage": 5.6797249171}, {"Entity": "Ukraine", "Year": 2017, "rank": 16, "renewable_percentage": 7.0457194664}, {"Entity": "Ukraine", "Year": 2018, "rank": 16, "renewable_percentage": 8.228528092}, {"Entity": "Ukraine", "Year": 2019, "rank": 16, "renewable_percentage": 7.7754487096}, {"Entity": "Ukraine", "Year": 2020, "rank": 16, "renewable_percentage": 11.8440577364}, {"Entity": "United Kingdom", "Year": 2000, "rank": 15, "renewable_percentage": 2.6657406913}, {"Entity": "United Kingdom", "Year": 2001, "rank": 15, "renewable_percentage": 2.5001961451}, {"Entity": "United Kingdom", "Year": 2002, "rank": 15, "renewable_percentage": 2.8939157566}, {"Entity": "United Kingdom", "Year": 2003, "rank": 15, "renewable_percentage": 2.6854802003}, {"Entity": "United Kingdom", "Year": 2004, "rank": 15, "renewable_percentage": 3.6136880575}, {"Entity": "United Kingdom", "Year": 2005, "rank": 15, "renewable_percentage": 4.2815234434}, {"Entity": "United Kingdom", "Year": 2006, "rank": 15, "renewable_percentage": 4.6029890199}, {"Entity": "United Kingdom", "Year": 2007, "rank": 15, "renewable_percentage": 5.0104331009}, {"Entity": "United Kingdom", "Year": 2008, "rank": 15, "renewable_percentage": 5.6776842324}, {"Entity": "United Kingdom", "Year": 2009, "rank": 14, "renewable_percentage": 6.7679854187}, {"Entity": "United Kingdom", "Year": 2010, "rank": 15, "renewable_percentage": 6.9092924441}, {"Entity": "United Kingdom", "Year": 2011, "rank": 13, "renewable_percentage": 9.6422505889}, {"Entity": "United Kingdom", "Year": 2012, "rank": 11, "renewable_percentage": 11.4273047189}, {"Entity": "United Kingdom", "Year": 2013, "rank": 10, "renewable_percentage": 14.9727052732}, {"Entity": "United Kingdom", "Year": 2014, "rank": 8, "renewable_percentage": 19.2476358104}, {"Entity": "United Kingdom", "Year": 2015, "rank": 6, "renewable_percentage": 24.6227709191}, {"Entity": "United Kingdom", "Year": 2016, "rank": 7, "renewable_percentage": 24.6788390627}, {"Entity": "United Kingdom", "Year": 2017, "rank": 6, "renewable_percentage": 29.4986571173}, {"Entity": "United Kingdom", "Year": 2018, "rank": 6, "renewable_percentage": 33.2919818457}, {"Entity": "United Kingdom", "Year": 2019, "rank": 5, "renewable_percentage": 37.4568630499}, {"Entity": "United Kingdom", "Year": 2020, "rank": 5, "renewable_percentage": 42.8603962651}, {"Entity": "United States", "Year": 2000, "rank": 10, "renewable_percentage": 9.2298992662}, {"Entity": "United States", "Year": 2001, "rank": 11, "renewable_percentage": 7.5132056541}, {"Entity": "United States", "Year": 2002, "rank": 10, "renewable_percentage": 8.749216358}, {"Entity": "United States", "Year": 2003, "rank": 10, "renewable_percentage": 9.0252110397}, {"Entity": "United States", "Year": 2004, "rank": 11, "renewable_percentage": 8.7334100887}, {"Entity": "United States", "Year": 2005, "rank": 12, "renewable_percentage": 8.7494640631}, {"Entity": "United States", "Year": 2006, "rank": 12, "renewable_percentage": 9.4184742052}, {"Entity": "United States", "Year": 2007, "rank": 12, "renewable_percentage": 8.3984096829}, {"Entity": "United States", "Year": 2008, "rank": 11, "renewable_percentage": 9.180943292}, {"Entity": "United States", "Year": 2009, "rank": 10, "renewable_percentage": 10.547689996}, {"Entity": "United States", "Year": 2010, "rank": 11, "renewable_percentage": 10.3180892283}, {"Entity": "United States", "Year": 2011, "rank": 9, "renewable_percentage": 12.4665249812}, {"Entity": "United States", "Year": 2012, "rank": 10, "renewable_percentage": 12.1841179804}, {"Entity": "United States", "Year": 2013, "rank": 12, "renewable_percentage": 12.8311154179}, {"Entity": "United States", "Year": 2014, "rank": 12, "renewable_percentage": 13.3503092033}, {"Entity": "United States", "Year": 2015, "rank": 14, "renewable_percentage": 13.6261352256}, {"Entity": "United States", "Year": 2016, "rank": 12, "renewable_percentage": 15.2880936304}, {"Entity": "United States", "Year": 2017, "rank": 9, "renewable_percentage": 17.4515276472}, {"Entity": "United States", "Year": 2018, "rank": 11, "renewable_percentage": 17.4499886946}, {"Entity": "United States", "Year": 2019, "rank": 13, "renewable_percentage": 18.2946243489}, {"Entity": "United States", "Year": 2020, "rank": 12, "renewable_percentage": 20.3156921037}], "metadata": {"Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}, "rank": {"type": "number", "semanticType": "Number"}, "renewable_percentage": {"type": "number", "semanticType": "Percentage"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Rank countries by renewable percentage within each year (highest percentage = rank 1)\n df_energy['rank'] = df_energy.groupby('Year')['renewable_percentage'].rank(\n method='dense', \n ascending=False\n )\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage', 'rank']].copy()\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 158029.9988, 190729.9957, 209229.9957, ..., 6993180.176, 9861099.609, 9874660.156, 10096009.77\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 90.14, 91.79, 92.54, 804.95\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Transform the data into a long format where different energy sources (fossil fuels, nuclear, renewables) are unpivoted into separate rows. Each row should contain the year, entity (country), energy source type, and the corresponding energy value in TWh. This will enable visualization of energy generation trends over time by source and country.\",\n \"display_instruction\": \"Show **energy generation** trends by **source** and **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"source\", \"energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n },\n \"reason\": \"The user wants to visualize energy data across different sources with a line chart faceted by source. The original data has energy sources in separate columns (fossil fuels, nuclear, renewables), so we need to unpivot these columns into a long format with 'source' and 'energy' fields. The chart_encodings provided by the user are appropriate for this visualization goal, using faceting (column) to separate different energy sources.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Unpivot the energy source columns into long format\n transformed_df = pd.melt(\n df_energy,\n id_vars=['Year', 'Entity'],\n value_vars=[\n 'Electricity from fossil fuels (TWh)',\n 'Electricity from nuclear (TWh)',\n 'Electricity from renewables (TWh)'\n ],\n var_name='source',\n value_name='energy'\n )\n \n # Clean up the source names to be more readable\n transformed_df['source'] = transformed_df['source'].str.replace('Electricity from ', '').str.replace(' (TWh)', '')\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Year energy source\n0 Australia 2000 181.05 fossil fuels\n1 Australia 2001 194.33 fossil fuels\n2 Australia 2002 197.29 fossil fuels\n3 Australia 2003 195.13 fossil fuels\n4 Australia 2004 203.66 fossil fuels\n5 Australia 2005 195.95 fossil fuels\n6 Australia 2006 198.72 fossil fuels\n7 Australia 2007 208.59 fossil fuels\n8 Australia 2008 211.06 fossil fuels\n9 Australia 2009 216.42 fossil fuels\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show renewable percentage for each country\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"energy\",\n \"color\": \"Entity\",\n \"column\": \"source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage for each country and year. The renewable percentage is computed as the ratio of renewable energy to total energy (sum of fossil fuels, nuclear, and renewables) multiplied by 100. The output should contain year, entity (country), and the renewable percentage value.\",\n \"display_instruction\": \"Show **renewable percentage** for each **Entity** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"renewable_percentage\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"renewable_percentage\",\n \"color\": \"Entity\"\n },\n \"reason\": \"The user wants to see renewable percentage trends, which requires calculating the proportion of renewable energy relative to total energy generation. This is a single metric per country per year, so we don't need the 'column' faceting by source anymore. The chart_encodings are updated to reflect that we're now showing a percentage metric rather than absolute energy values by source.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage']].copy()\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Year renewable_percentage\n0 Australia 2000 8.634437\n1 Australia 2001 8.218014\n2 Australia 2002 8.083302\n3 Australia 2003 8.659832\n4 Australia 2004 8.701305\n5 Australia 2005 9.156236\n6 Australia 2006 9.635760\n7 Australia 2007 9.119031\n8 Australia 2008 8.054890\n9 Australia 2009 7.804379\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"rank countries by their renewable percentage\",\n \"chart_type\": \"Line Chart\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"renewable_percentage\",\n \"color\": \"Entity\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage for each country and year, then rank countries based on their renewable percentage. The ranking should be computed for each year, showing which countries have the highest to lowest renewable percentage. The output should contain year, entity (country), renewable percentage, and the rank of each country within that year.\",\n \"display_instruction\": \"Show **countries ranked** by **renewable percentage** over **Year**\",\n \"output_fields\": [\"Year\", \"Entity\", \"renewable_percentage\", \"rank\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"renewable_percentage\",\n \"color\": \"Entity\"\n },\n \"reason\": \"The user wants to rank countries by their renewable percentage, which requires adding a rank field that orders countries within each year based on their renewable percentage (highest percentage = rank 1). This allows comparison of countries' relative positions in renewable energy adoption over time. The chart_encodings remain the same as the previous step since we're still visualizing renewable percentage trends, but now with ranking information available.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Rank countries by renewable percentage within each year (highest percentage = rank 1)\n df_energy['rank'] = df_energy.groupby('Year')['renewable_percentage'].rank(\n method='dense', \n ascending=False\n )\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage', 'rank']].copy()\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-45", "resultTableId": "table-78", "chart": {"id": "chart-1760738441793", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-renewable_percentage-1760738424337"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-45", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "rank countries by their renewable percentage", "displayContent": "Show **countries ranked** by **renewable percentage** over **Year**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "- Calculate **total_energy** for each country-year by summing electricity generated from **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n- Compute **renewable_percentage** by dividing **Electricity from renewables (TWh)** by **total_energy** and multiplying by **100**\n- Replace any infinite values in **renewable_percentage** with NaN to handle cases where total energy is zero\n- Assign a **rank** to each country within each **Year** based on **renewable_percentage**, where rank **1** represents the highest renewable percentage (using dense ranking method)\n- Return a dataset containing **Year**, **Entity** (country name), **renewable_percentage**, and **rank**", "concepts": [{"explanation": "The proportion of a country's total electricity generation that comes from renewable sources, expressed as a percentage. Calculated as: \\[ \\text{renewable\\_percentage} = \\frac{\\text{Electricity from renewables (TWh)}}{\\text{total\\_energy}} \\times 100 \\]", "field": "renewable_percentage"}], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 190729.9957, 227580.0018, 233600.0061, ..., 9282549.805, 9861099.609, 9874660.156, 10096009.77\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 88.76, 90.14, 91.79, 92.54\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total energy for each row\n df_energy['total_energy'] = (\n df_energy['Electricity from fossil fuels (TWh)'] + \n df_energy['Electricity from nuclear (TWh)'] + \n df_energy['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_energy['renewable_percentage'] = (\n df_energy['Electricity from renewables (TWh)'] / df_energy['total_energy'] * 100\n )\n \n # Handle division by zero cases\n df_energy['renewable_percentage'] = df_energy['renewable_percentage'].replace([np.inf, -np.inf], np.nan)\n \n # Rank countries by renewable percentage within each year (highest percentage = rank 1)\n df_energy['rank'] = df_energy.groupby('Year')['renewable_percentage'].rank(\n method='dense', \n ascending=False\n )\n \n # Select only the required columns\n transformed_df = df_energy[['Year', 'Entity', 'renewable_percentage', 'rank']].copy()\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\n- Calculate **total_energy** for each country-year by summing electricity generated from **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n- Compute **renewable_percentage** by dividing **Electricity from renewables (TWh)** by **total_energy** and multiplying by **100**\n- Replace any infinite values in **renewable_percentage** with NaN to handle cases where total energy is zero\n- Assign a **rank** to each country within each **Year** based on **renewable_percentage**, where rank **1** represents the highest renewable percentage (using dense ranking method)\n- Return a dataset containing **Year**, **Entity** (country name), **renewable_percentage**, and **rank**\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"renewable_percentage\",\n \"explanation\": \"The proportion of a country's total electricity generation that comes from renewable sources, expressed as a percentage. Calculated as: \\\\[ \\\\text{renewable\\\\_percentage} = \\\\frac{\\\\text{Electricity from renewables (TWh)}}{\\\\text{total\\\\_energy}} \\\\times 100 \\\\]\"\n }\n]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-97", "displayId": "renewable-elec", "names": ["Electricity from renewables (TWh)", "Entity", "Year"], "rows": [{"Electricity from renewables (TWh)": 17.11, "Entity": "Australia", "Year": "2000"}, {"Electricity from renewables (TWh)": 63.99, "Entity": "Australia", "Year": "2020"}, {"Electricity from renewables (TWh)": 308.77, "Entity": "Brazil", "Year": "2000"}, {"Electricity from renewables (TWh)": 520.01, "Entity": "Brazil", "Year": "2020"}, {"Electricity from renewables (TWh)": 363.7, "Entity": "Canada", "Year": "2000"}, {"Electricity from renewables (TWh)": 429.24, "Entity": "Canada", "Year": "2020"}, {"Electricity from renewables (TWh)": 225.56, "Entity": "China", "Year": "2000"}, {"Electricity from renewables (TWh)": 2184.94, "Entity": "China", "Year": "2020"}, {"Electricity from renewables (TWh)": 67.83, "Entity": "France", "Year": "2000"}, {"Electricity from renewables (TWh)": 125.28, "Entity": "France", "Year": "2020"}, {"Electricity from renewables (TWh)": 35.47, "Entity": "Germany", "Year": "2000"}, {"Electricity from renewables (TWh)": 251.48, "Entity": "Germany", "Year": "2020"}, {"Electricity from renewables (TWh)": 80.27, "Entity": "India", "Year": "2000"}, {"Electricity from renewables (TWh)": 315.76, "Entity": "India", "Year": "2020"}, {"Electricity from renewables (TWh)": 19.6, "Entity": "Indonesia", "Year": "2000"}, {"Electricity from renewables (TWh)": 52.91, "Entity": "Indonesia", "Year": "2020"}, {"Electricity from renewables (TWh)": 50.87, "Entity": "Italy", "Year": "2000"}, {"Electricity from renewables (TWh)": 116.9, "Entity": "Italy", "Year": "2020"}, {"Electricity from renewables (TWh)": 104.16, "Entity": "Japan", "Year": "2000"}, {"Electricity from renewables (TWh)": 205.6, "Entity": "Japan", "Year": "2020"}, {"Electricity from renewables (TWh)": 7.53, "Entity": "Kazakhstan", "Year": "2000"}, {"Electricity from renewables (TWh)": 11.94, "Entity": "Kazakhstan", "Year": "2020"}, {"Electricity from renewables (TWh)": 44.51, "Entity": "Mexico", "Year": "2000"}, {"Electricity from renewables (TWh)": 69.19, "Entity": "Mexico", "Year": "2020"}, {"Electricity from renewables (TWh)": 2.33, "Entity": "Poland", "Year": "2000"}, {"Electricity from renewables (TWh)": 28.23, "Entity": "Poland", "Year": "2020"}, {"Electricity from renewables (TWh)": 0, "Entity": "Saudi Arabia", "Year": "2000"}, {"Electricity from renewables (TWh)": 0.21, "Entity": "Saudi Arabia", "Year": "2020"}, {"Electricity from renewables (TWh)": 1.79, "Entity": "South Africa", "Year": "2000"}, {"Electricity from renewables (TWh)": 12.83, "Entity": "South Africa", "Year": "2020"}, {"Electricity from renewables (TWh)": 34.49, "Entity": "Spain", "Year": "2000"}, {"Electricity from renewables (TWh)": 113.79, "Entity": "Spain", "Year": "2020"}, {"Electricity from renewables (TWh)": 6.38, "Entity": "Thailand", "Year": "2000"}, {"Electricity from renewables (TWh)": 24.73, "Entity": "Thailand", "Year": "2020"}, {"Electricity from renewables (TWh)": 11.28, "Entity": "Ukraine", "Year": "2000"}, {"Electricity from renewables (TWh)": 17.56, "Entity": "Ukraine", "Year": "2020"}, {"Electricity from renewables (TWh)": 9.98, "Entity": "United Kingdom", "Year": "2000"}, {"Electricity from renewables (TWh)": 131.74, "Entity": "United Kingdom", "Year": "2020"}, {"Electricity from renewables (TWh)": 350.93, "Entity": "United States", "Year": "2000"}, {"Electricity from renewables (TWh)": 821.4, "Entity": "United States", "Year": "2020"}], "metadata": {"Electricity from renewables (TWh)": {"type": "number", "semanticType": "Number"}, "Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 61.99, 62.21, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"compare each countries renewable between 2000 and 2020\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Energy\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Compare renewable energy (Electricity from renewables) for each country between the years 2000 and 2020. Filter the data to include only years 2000 and 2020, and prepare the output with country names, year, and renewable energy values for visualization as a grouped bar chart.\",\n \"display_instruction\": \"Compare **renewable energy** by **country** between **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Electricity from renewables (TWh)\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to compare renewable energy across countries between 2000 and 2020. The output field 'Renewable Energy' mentioned in the original chart_encodings maps to 'Electricity from renewables (TWh)' in the dataset. To create a grouped bar chart comparing these two years, we need to filter the data to only include years 2000 and 2020, and output the Entity (country), Year, and the renewable energy values. The chart_encodings are updated to use the actual column name from the dataset.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "global-energy-20-small.csv", "resultTableId": "table-97", "chart": {"id": "chart-1760738769634", "chartType": "Grouped Bar Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "y": {"fieldID": "concept-1760738743125"}, "color": {"channel": "color", "bin": false, "fieldID": "original--global-energy-20-small.csv--Year"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}}, "tableRef": "global-energy-20-small.csv", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "compare each countries renewable between 2000 and 2020", "displayContent": "Compare **renewable energy** by **country** between **2000** and **2020**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code performs a straightforward comparison analysis of renewable energy generation across countries:\n\n- **Filters** the dataset to include only data from years **2000** and **2020**, creating a 20-year comparison window\n- **Selects** three key columns: `Entity` (country name), `Year`, and `Electricity from renewables (TWh)` (renewable energy generation)\n- **Converts** the `Year` field to string format to treat it as a categorical variable for visualization purposes\n- **Sorts** the results by `Entity` and `Year` to organize countries alphabetically with their respective year data grouped together\n- **Returns** a cleaned dataset showing how renewable electricity generation has changed for each country between 2000 and 2020", "concepts": [], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 10006669.92, 10502929.69, 10707219.73, nan\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 56.18, 61.99, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code performs a straightforward comparison analysis of renewable energy generation across countries:\n\n- **Filters** the dataset to include only data from years **2000** and **2020**, creating a 20-year comparison window\n- **Selects** three key columns: `Entity` (country name), `Year`, and `Electricity from renewables (TWh)` (renewable energy generation)\n- **Converts** the `Year` field to string format to treat it as a categorical variable for visualization purposes\n- **Sorts** the results by `Entity` and `Year` to organize countries alphabetically with their respective year data grouped together\n- **Returns** a cleaned dataset showing how renewable electricity generation has changed for each country between 2000 and 2020\n\n[CONCEPTS EXPLANATION]\n\n```json\n[]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-27", "displayId": "renewable-energy1", "names": ["Entity", "Renewable Percentage", "Year"], "rows": [{"Entity": "Australia", "Renewable Percentage": 8.6344368187, "Year": "2000"}, {"Entity": "Australia", "Renewable Percentage": 25.5031684668, "Year": "2020"}, {"Entity": "Brazil", "Renewable Percentage": 90.1307723743, "Year": "2000"}, {"Entity": "Brazil", "Renewable Percentage": 84.6411771408, "Year": "2020"}, {"Entity": "Canada", "Renewable Percentage": 61.8095917882, "Year": "2000"}, {"Entity": "Canada", "Renewable Percentage": 68.7796436354, "Year": "2020"}, {"Entity": "China", "Renewable Percentage": 16.639126586, "Year": "2000"}, {"Entity": "China", "Renewable Percentage": 28.2464606924, "Year": "2020"}, {"Entity": "France", "Renewable Percentage": 12.7117691154, "Year": "2000"}, {"Entity": "France", "Renewable Percentage": 23.7610241821, "Year": "2020"}, {"Entity": "Germany", "Renewable Percentage": 6.1977983575, "Year": "2000"}, {"Entity": "Germany", "Renewable Percentage": 44.3324048937, "Year": "2020"}, {"Entity": "Global Average", "Renewable Percentage": 16.4213212559, "Year": "2000"}, {"Entity": "Global Average", "Renewable Percentage": 29.2955247263, "Year": "2020"}, {"Entity": "India", "Renewable Percentage": 14.0481982534, "Year": "2000"}, {"Entity": "India", "Renewable Percentage": 20.2059243238, "Year": "2020"}, {"Entity": "Indonesia", "Renewable Percentage": null, "Year": "2000"}, {"Entity": "Indonesia", "Renewable Percentage": null, "Year": "2020"}, {"Entity": "Italy", "Renewable Percentage": 18.900241501, "Year": "2000"}, {"Entity": "Italy", "Renewable Percentage": 42.0397741576, "Year": "2020"}, {"Entity": "Japan", "Renewable Percentage": 10.5382436261, "Year": "2000"}, {"Entity": "Japan", "Renewable Percentage": 21.324925062, "Year": "2020"}, {"Entity": "Kazakhstan", "Renewable Percentage": null, "Year": "2000"}, {"Entity": "Kazakhstan", "Renewable Percentage": null, "Year": "2020"}, {"Entity": "Mexico", "Renewable Percentage": 22.9291160107, "Year": "2000"}, {"Entity": "Mexico", "Renewable Percentage": 21.2552224134, "Year": "2020"}, {"Entity": "Poland", "Renewable Percentage": 1.6273222517, "Year": "2000"}, {"Entity": "Poland", "Renewable Percentage": 17.9648720886, "Year": "2020"}, {"Entity": "Saudi Arabia", "Renewable Percentage": null, "Year": "2000"}, {"Entity": "Saudi Arabia", "Renewable Percentage": null, "Year": "2020"}, {"Entity": "South Africa", "Renewable Percentage": 0.9110805721, "Year": "2000"}, {"Entity": "South Africa", "Renewable Percentage": 5.780581212, "Year": "2020"}, {"Entity": "Spain", "Renewable Percentage": 15.6119862394, "Year": "2000"}, {"Entity": "Spain", "Renewable Percentage": 43.8108805298, "Year": "2020"}, {"Entity": "Thailand", "Renewable Percentage": 7.1261029822, "Year": "2000"}, {"Entity": "Thailand", "Renewable Percentage": 13.7963737796, "Year": "2020"}, {"Entity": "Ukraine", "Renewable Percentage": 6.5860921352, "Year": "2000"}, {"Entity": "Ukraine", "Renewable Percentage": 11.8440577364, "Year": "2020"}, {"Entity": "United Kingdom", "Renewable Percentage": 2.6657406913, "Year": "2000"}, {"Entity": "United Kingdom", "Renewable Percentage": 42.8603962651, "Year": "2020"}, {"Entity": "United States", "Renewable Percentage": 9.2298992662, "Year": "2000"}, {"Entity": "United States", "Renewable Percentage": 20.3156921037, "Year": "2020"}], "metadata": {"Entity": {"type": "string", "semanticType": "Name"}, "Renewable Percentage": {"type": "number", "semanticType": "Percentage"}, "Year": {"type": "number", "semanticType": "Year"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 61.99, 62.21, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"compare each countries renewable between 2000 and 2020\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Energy\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Compare renewable energy (Electricity from renewables) for each country between the years 2000 and 2020. Filter the data to include only years 2000 and 2020, and prepare the output with country names, year, and renewable energy values for visualization as a grouped bar chart.\",\n \"display_instruction\": \"Compare **renewable energy** by **country** between **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Electricity from renewables (TWh)\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to compare renewable energy across countries between 2000 and 2020. The output field 'Renewable Energy' mentioned in the original chart_encodings maps to 'Electricity from renewables (TWh)' in the dataset. To create a grouped bar chart comparing these two years, we need to filter the data to only include years 2000 and 2020, and output the Entity (country), Year, and the renewable energy values. The chart_encodings are updated to use the actual column name from the dataset.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Electricity from renewables (TWh) Entity Year\n0 17.11 Australia 2000\n1 63.99 Australia 2020\n2 308.77 Brazil 2000\n3 520.01 Brazil 2020\n4 363.70 Canada 2000\n5 429.24 Canada 2020\n6 225.56 China 2000\n7 2184.94 China 2020\n8 67.83 France 2000\n9 125.28 France 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show their renewable percentage instead, and add an entity to show global average\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage (proportion of renewables to total electricity generation from all sources) for each country between 2000 and 2020. Add a 'Global Average' entity that represents the worldwide average renewable percentage for each year. The output should include Entity (with 'Global Average' added), Year, and the renewable percentage.\",\n \"display_instruction\": \"Show **renewable energy percentage** by **country** with **global average** for **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Renewable Percentage\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Percentage\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to see renewable percentage instead of absolute values, and wants to add a global average entity for comparison. Renewable percentage is calculated as the ratio of renewable energy to total electricity generation (fossil fuels + nuclear + renewables). A 'Global Average' entity needs to be computed by aggregating all countries' data for each year. The y-axis encoding is updated to reflect the new metric 'Renewable Percentage'.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-97", "resultTableId": "table-27", "chart": {"id": "chart-1760738813383", "chartType": "Grouped Bar Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "y": {"fieldID": "original--global-energy-20-small.csv--Electricity from renewables (TWh)"}, "color": {"fieldID": "original--global-energy-20-small.csv--Year"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-97", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "show their renewable percentage instead, and add an entity to show global average", "displayContent": "Show **renewable energy percentage** by **country** with **global average** for **2000** and **2020**"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code performs the following transformation steps:\n\n1. **Filter data** to include only records from **2000** and **2020**\n2. Calculate **Total Electricity** generation by summing three sources: **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n3. Compute **Renewable Percentage** for each country and year by dividing **Electricity from renewables** by **Total Electricity** and multiplying by 100\n4. Extract relevant columns: **Entity** (country name), **Year**, and **Renewable Percentage**\n5. Calculate **Global Average** renewable percentage for each year by:\n - Summing all countries' **renewable electricity** generation\n - Dividing by the sum of all countries' **total electricity** generation\n - Multiplying by 100 to get percentage\n6. Combine individual country data with the **Global Average** statistics\n7. Convert **Year** values to string format\n8. Sort results by **Entity** name and **Year**", "concepts": [{"explanation": "The sum of electricity generated from all three sources (fossil fuels, nuclear, and renewables) measured in terawatt-hours (TWh). This represents the total electricity production capacity for each country.", "field": "Total Electricity"}, {"explanation": "The proportion of electricity generated from renewable sources relative to total electricity production, expressed as a percentage: \\( \\text{Renewable Percentage} = \\frac{\\text{Electricity from renewables}}{\\text{Total Electricity}} \\times 100 \\). This metric indicates the extent of renewable energy adoption in a country's electricity mix.", "field": "Renewable Percentage"}], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 10096009.77, 10502929.69, 10707219.73, nan\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., nan, nan, nan, nan\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code performs the following transformation steps:\n\n1. **Filter data** to include only records from **2000** and **2020**\n2. Calculate **Total Electricity** generation by summing three sources: **fossil fuels**, **nuclear**, and **renewables** (all measured in TWh)\n3. Compute **Renewable Percentage** for each country and year by dividing **Electricity from renewables** by **Total Electricity** and multiplying by 100\n4. Extract relevant columns: **Entity** (country name), **Year**, and **Renewable Percentage**\n5. Calculate **Global Average** renewable percentage for each year by:\n - Summing all countries' **renewable electricity** generation\n - Dividing by the sum of all countries' **total electricity** generation\n - Multiplying by 100 to get percentage\n6. Combine individual country data with the **Global Average** statistics\n7. Convert **Year** values to string format\n8. Sort results by **Entity** name and **Year**\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"Total Electricity\",\n \"explanation\": \"The sum of electricity generated from all three sources (fossil fuels, nuclear, and renewables) measured in terawatt-hours (TWh). This represents the total electricity production capacity for each country.\"\n },\n {\n \"field\": \"Renewable Percentage\",\n \"explanation\": \"The proportion of electricity generated from renewable sources relative to total electricity production, expressed as a percentage: \\\\( \\\\text{Renewable Percentage} = \\\\frac{\\\\text{Electricity from renewables}}{\\\\text{Total Electricity}} \\\\times 100 \\\\). This metric indicates the extent of renewable energy adoption in a country's electricity mix.\"\n }\n]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-81", "displayId": "energy-source1", "names": ["Energy", "Energy Source", "Year"], "rows": [{"Energy": 7160.71, "Energy Source": "Fossil Fuels", "Year": 2000}, {"Energy": 1996.65, "Energy Source": "Nuclear", "Year": 2000}, {"Energy": 1742.56, "Energy Source": "Renewables", "Year": 2000}, {"Energy": 7273.89, "Energy Source": "Fossil Fuels", "Year": 2001}, {"Energy": 2037.54, "Energy Source": "Nuclear", "Year": 2001}, {"Energy": 1690.11, "Energy Source": "Renewables", "Year": 2001}, {"Energy": 7621.07, "Energy Source": "Fossil Fuels", "Year": 2002}, {"Energy": 2042.18, "Energy Source": "Nuclear", "Year": 2002}, {"Energy": 1757.63, "Energy Source": "Renewables", "Year": 2002}, {"Energy": 8043.86, "Energy Source": "Fossil Fuels", "Year": 2003}, {"Energy": 1998.52, "Energy Source": "Nuclear", "Year": 2003}, {"Energy": 1804.52, "Energy Source": "Renewables", "Year": 2003}, {"Energy": 8399.72, "Energy Source": "Fossil Fuels", "Year": 2004}, {"Energy": 2095, "Energy Source": "Nuclear", "Year": 2004}, {"Energy": 1952.72, "Energy Source": "Renewables", "Year": 2004}, {"Energy": 8828.43, "Energy Source": "Fossil Fuels", "Year": 2005}, {"Energy": 2094.4, "Energy Source": "Nuclear", "Year": 2005}, {"Energy": 2025.26, "Energy Source": "Renewables", "Year": 2005}, {"Energy": 9183.05, "Energy Source": "Fossil Fuels", "Year": 2006}, {"Energy": 2120.38, "Energy Source": "Nuclear", "Year": 2006}, {"Energy": 2165.94, "Energy Source": "Renewables", "Year": 2006}, {"Energy": 9853.09, "Energy Source": "Fossil Fuels", "Year": 2007}, {"Energy": 2067.04, "Energy Source": "Nuclear", "Year": 2007}, {"Energy": 2256.79, "Energy Source": "Renewables", "Year": 2007}, {"Energy": 9817.15, "Energy Source": "Fossil Fuels", "Year": 2008}, {"Energy": 2043.94, "Energy Source": "Nuclear", "Year": 2008}, {"Energy": 2496.03, "Energy Source": "Renewables", "Year": 2008}, {"Energy": 9686.86, "Energy Source": "Fossil Fuels", "Year": 2009}, {"Energy": 2017.25, "Energy Source": "Nuclear", "Year": 2009}, {"Energy": 2563.95, "Energy Source": "Renewables", "Year": 2009}, {"Energy": 10427.03, "Energy Source": "Fossil Fuels", "Year": 2010}, {"Energy": 2083.37, "Energy Source": "Nuclear", "Year": 2010}, {"Energy": 2802.89, "Energy Source": "Renewables", "Year": 2010}, {"Energy": 10974.83, "Energy Source": "Fossil Fuels", "Year": 2011}, {"Energy": 1956, "Energy Source": "Nuclear", "Year": 2011}, {"Energy": 2997.29, "Energy Source": "Renewables", "Year": 2011}, {"Energy": 11277.49, "Energy Source": "Fossil Fuels", "Year": 2012}, {"Energy": 1788.26, "Energy Source": "Nuclear", "Year": 2012}, {"Energy": 3226.1, "Energy Source": "Renewables", "Year": 2012}, {"Energy": 11561.86, "Energy Source": "Fossil Fuels", "Year": 2013}, {"Energy": 1813, "Energy Source": "Nuclear", "Year": 2013}, {"Energy": 3473.9, "Energy Source": "Renewables", "Year": 2013}, {"Energy": 11761.51, "Energy Source": "Fossil Fuels", "Year": 2014}, {"Energy": 1847.87, "Energy Source": "Nuclear", "Year": 2014}, {"Energy": 3753.03, "Energy Source": "Renewables", "Year": 2014}, {"Energy": 11653.61, "Energy Source": "Fossil Fuels", "Year": 2015}, {"Energy": 1886.61, "Energy Source": "Nuclear", "Year": 2015}, {"Energy": 3903.7, "Energy Source": "Renewables", "Year": 2015}, {"Energy": 11785.35, "Energy Source": "Fossil Fuels", "Year": 2016}, {"Energy": 1906.92, "Energy Source": "Nuclear", "Year": 2016}, {"Energy": 4186.83, "Energy Source": "Renewables", "Year": 2016}, {"Energy": 12003.24, "Energy Source": "Fossil Fuels", "Year": 2017}, {"Energy": 1942.94, "Energy Source": "Nuclear", "Year": 2017}, {"Energy": 4500.22, "Energy Source": "Renewables", "Year": 2017}, {"Energy": 12445.24, "Energy Source": "Fossil Fuels", "Year": 2018}, {"Energy": 2016.82, "Energy Source": "Nuclear", "Year": 2018}, {"Energy": 4834.65, "Energy Source": "Renewables", "Year": 2018}, {"Energy": 12355.91, "Energy Source": "Fossil Fuels", "Year": 2019}, {"Energy": 2073.87, "Energy Source": "Nuclear", "Year": 2019}, {"Energy": 5146.11, "Energy Source": "Renewables", "Year": 2019}, {"Energy": 12032.75, "Energy Source": "Fossil Fuels", "Year": 2020}, {"Energy": 1974.46, "Energy Source": "Nuclear", "Year": 2020}, {"Energy": 5497.73, "Energy Source": "Renewables", "Year": 2020}], "metadata": {"Energy": {"type": "number", "semanticType": "Number"}, "Energy Source": {"type": "string", "semanticType": "String", "levels": ["Fossil Fuels", "Nuclear", "Renewables"]}, "Year": {"type": "number", "semanticType": "Year"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Group by Year and sum electricity generation from all countries\n global_energy = df_energy.groupby('Year').agg({\n 'Electricity from fossil fuels (TWh)': 'sum',\n 'Electricity from nuclear (TWh)': 'sum',\n 'Electricity from renewables (TWh)': 'sum'\n }).reset_index()\n \n # Rename columns for clarity\n global_energy.columns = ['Year', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n global_energy,\n id_vars=['Year'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Year and Energy Source\n transformed_df = transformed_df.sort_values(['Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 61.99, 62.21, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"compare each countries renewable between 2000 and 2020\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Energy\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Compare renewable energy (Electricity from renewables) for each country between the years 2000 and 2020. Filter the data to include only years 2000 and 2020, and prepare the output with country names, year, and renewable energy values for visualization as a grouped bar chart.\",\n \"display_instruction\": \"Compare **renewable energy** by **country** between **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Electricity from renewables (TWh)\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to compare renewable energy across countries between 2000 and 2020. The output field 'Renewable Energy' mentioned in the original chart_encodings maps to 'Electricity from renewables (TWh)' in the dataset. To create a grouped bar chart comparing these two years, we need to filter the data to only include years 2000 and 2020, and output the Entity (country), Year, and the renewable energy values. The chart_encodings are updated to use the actual column name from the dataset.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Electricity from renewables (TWh) Entity Year\n0 17.11 Australia 2000\n1 63.99 Australia 2020\n2 308.77 Brazil 2000\n3 520.01 Brazil 2020\n4 363.70 Canada 2000\n5 429.24 Canada 2020\n6 225.56 China 2000\n7 2184.94 China 2020\n8 67.83 France 2000\n9 125.28 France 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show their renewable percentage instead, and add an entity to show global average\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage (proportion of renewables to total electricity generation from all sources) for each country between 2000 and 2020. Add a 'Global Average' entity that represents the worldwide average renewable percentage for each year. The output should include Entity (with 'Global Average' added), Year, and the renewable percentage.\",\n \"display_instruction\": \"Show **renewable energy percentage** by **country** with **global average** for **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Renewable Percentage\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Percentage\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to see renewable percentage instead of absolute values, and wants to add a global average entity for comparison. Renewable percentage is calculated as the ratio of renewable energy to total electricity generation (fossil fuels + nuclear + renewables). A 'Global Average' entity needs to be computed by aggregating all countries' data for each year. The y-axis encoding is updated to reflect the new metric 'Renewable Percentage'.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Renewable Percentage Year\n0 Australia 8.634437 2000\n1 Australia 25.503168 2020\n2 Brazil 90.130772 2000\n3 Brazil 84.641177 2020\n4 Canada 61.809592 2000\n5 Canada 68.779644 2020\n6 China 16.639127 2000\n7 China 28.246461 2020\n8 France 12.711769 2000\n9 France 23.761024 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show global energy composition over time\",\n \"chart_type\": \"Custom Area\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Show the global energy composition over time by aggregating electricity generation from all countries for each year, broken down by energy source (fossil fuels, nuclear, and renewables). The output should be in long format with Year, Energy Source, and Energy values to support a stacked area chart visualization.\",\n \"display_instruction\": \"Show global **energy composition** by **energy source** over time\",\n \"output_fields\": [\"Year\", \"Energy Source\", \"Energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n },\n \"reason\": \"The user wants to visualize global energy composition over time, which requires aggregating electricity generation data across all countries for each year and breaking it down by energy source type. The data needs to be transformed into long format where each row represents a year-energy source combination, with the total energy value for that source globally. This follows up from the previous renewable percentage analysis by showing the overall energy mix trends rather than focusing on specific countries or percentages.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Group by Year and sum electricity generation from all countries\n global_energy = df_energy.groupby('Year').agg({\n 'Electricity from fossil fuels (TWh)': 'sum',\n 'Electricity from nuclear (TWh)': 'sum',\n 'Electricity from renewables (TWh)': 'sum'\n }).reset_index()\n \n # Rename columns for clarity\n global_energy.columns = ['Year', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n global_energy,\n id_vars=['Year'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Year and Energy Source\n transformed_df = transformed_df.sort_values(['Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-27", "resultTableId": "table-81", "chart": {"id": "chart-1760738942326", "chartType": "Custom Area", "encodingMap": {"x": {"channel": "x", "bin": false, "fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"channel": "y", "bin": false, "fieldID": "concept-1760738917347"}, "x2": {"channel": "x2", "bin": false}, "y2": {"channel": "y2", "bin": false}, "color": {"channel": "color", "bin": false, "fieldID": "concept-1760738921927"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-27", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "show global energy composition over time", "displayContent": "Show global **energy composition** by **energy source** over time"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "- Group the energy data by **Year** and aggregate electricity generation values across all countries by summing **Electricity from fossil fuels (TWh)**, **Electricity from nuclear (TWh)**, and **Electricity from renewables (TWh)**\n- Rename the aggregated columns to simplified labels: **Fossil Fuels**, **Nuclear**, and **Renewables**\n- Transform the data from wide format to long format by unpivoting the three energy source columns into two columns: **Energy Source** (containing the type of energy) and **Energy** (containing the generation value in TWh)\n- Sort the resulting dataset by **Year** and **Energy Source** for consistent ordering", "concepts": [], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 158029.9988, 190729.9957, 209229.9957, ..., nan, 4956060.059, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., nan, nan, nan, nan\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Group by Year and sum electricity generation from all countries\n global_energy = df_energy.groupby('Year').agg({\n 'Electricity from fossil fuels (TWh)': 'sum',\n 'Electricity from nuclear (TWh)': 'sum',\n 'Electricity from renewables (TWh)': 'sum'\n }).reset_index()\n \n # Rename columns for clarity\n global_energy.columns = ['Year', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n global_energy,\n id_vars=['Year'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Year and Energy Source\n transformed_df = transformed_df.sort_values(['Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\n- Group the energy data by **Year** and aggregate electricity generation values across all countries by summing **Electricity from fossil fuels (TWh)**, **Electricity from nuclear (TWh)**, and **Electricity from renewables (TWh)**\n- Rename the aggregated columns to simplified labels: **Fossil Fuels**, **Nuclear**, and **Renewables**\n- Transform the data from wide format to long format by unpivoting the three energy source columns into two columns: **Energy Source** (containing the type of energy) and **Energy** (containing the generation value in TWh)\n- Sort the resulting dataset by **Year** and **Energy Source** for consistent ordering\n\n[CONCEPTS EXPLANATION]\n\n```json\n[]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}, {"kind": "table", "id": "table-10", "displayId": "energy-source2", "names": ["Energy", "Energy Source", "Entity", "Year"], "rows": [{"Energy": 1113.3, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2000}, {"Energy": 16.74, "Energy Source": "Nuclear", "Entity": "China", "Year": 2000}, {"Energy": 225.56, "Energy Source": "Renewables", "Entity": "China", "Year": 2000}, {"Energy": 1182.59, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2001}, {"Energy": 17.47, "Energy Source": "Nuclear", "Entity": "China", "Year": 2001}, {"Energy": 280.73, "Energy Source": "Renewables", "Entity": "China", "Year": 2001}, {"Energy": 1337.46, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2002}, {"Energy": 25.13, "Energy Source": "Nuclear", "Entity": "China", "Year": 2002}, {"Energy": 291.41, "Energy Source": "Renewables", "Entity": "China", "Year": 2002}, {"Energy": 1579.96, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2003}, {"Energy": 43.34, "Energy Source": "Nuclear", "Entity": "China", "Year": 2003}, {"Energy": 287.28, "Energy Source": "Renewables", "Entity": "China", "Year": 2003}, {"Energy": 1795.41, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2004}, {"Energy": 50.47, "Energy Source": "Nuclear", "Entity": "China", "Year": 2004}, {"Energy": 357.43, "Energy Source": "Renewables", "Entity": "China", "Year": 2004}, {"Energy": 2042.8, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2005}, {"Energy": 53.09, "Energy Source": "Nuclear", "Entity": "China", "Year": 2005}, {"Energy": 404.37, "Energy Source": "Renewables", "Entity": "China", "Year": 2005}, {"Energy": 2364.16, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2006}, {"Energy": 54.84, "Energy Source": "Nuclear", "Entity": "China", "Year": 2006}, {"Energy": 446.72, "Energy Source": "Renewables", "Entity": "China", "Year": 2006}, {"Energy": 2718.7, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2007}, {"Energy": 62.13, "Energy Source": "Nuclear", "Entity": "China", "Year": 2007}, {"Energy": 500.71, "Energy Source": "Renewables", "Entity": "China", "Year": 2007}, {"Energy": 2762.29, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2008}, {"Energy": 68.39, "Energy Source": "Nuclear", "Entity": "China", "Year": 2008}, {"Energy": 665.08, "Energy Source": "Renewables", "Entity": "China", "Year": 2008}, {"Energy": 2980.2, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2009}, {"Energy": 70.05, "Energy Source": "Nuclear", "Entity": "China", "Year": 2009}, {"Energy": 664.39, "Energy Source": "Renewables", "Entity": "China", "Year": 2009}, {"Energy": 3326.19, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2010}, {"Energy": 74.74, "Energy Source": "Nuclear", "Entity": "China", "Year": 2010}, {"Energy": 786.38, "Energy Source": "Renewables", "Entity": "China", "Year": 2010}, {"Energy": 3811.77, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2011}, {"Energy": 87.2, "Energy Source": "Nuclear", "Entity": "China", "Year": 2011}, {"Energy": 792.38, "Energy Source": "Renewables", "Entity": "China", "Year": 2011}, {"Energy": 3869.38, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2012}, {"Energy": 98.32, "Energy Source": "Nuclear", "Entity": "China", "Year": 2012}, {"Energy": 999.56, "Energy Source": "Renewables", "Entity": "China", "Year": 2012}, {"Energy": 4203.77, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2013}, {"Energy": 111.5, "Energy Source": "Nuclear", "Entity": "China", "Year": 2013}, {"Energy": 1093.37, "Energy Source": "Renewables", "Entity": "China", "Year": 2013}, {"Energy": 4345.86, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2014}, {"Energy": 133.22, "Energy Source": "Nuclear", "Entity": "China", "Year": 2014}, {"Energy": 1289.23, "Energy Source": "Renewables", "Entity": "China", "Year": 2014}, {"Energy": 4222.76, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2015}, {"Energy": 171.38, "Energy Source": "Nuclear", "Entity": "China", "Year": 2015}, {"Energy": 1393.66, "Energy Source": "Renewables", "Entity": "China", "Year": 2015}, {"Energy": 4355, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2016}, {"Energy": 213.18, "Energy Source": "Nuclear", "Entity": "China", "Year": 2016}, {"Energy": 1522.79, "Energy Source": "Renewables", "Entity": "China", "Year": 2016}, {"Energy": 4643.1, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2017}, {"Energy": 248.1, "Energy Source": "Nuclear", "Entity": "China", "Year": 2017}, {"Energy": 1667.06, "Energy Source": "Renewables", "Entity": "China", "Year": 2017}, {"Energy": 4990.28, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2018}, {"Energy": 295, "Energy Source": "Nuclear", "Entity": "China", "Year": 2018}, {"Energy": 1835.32, "Energy Source": "Renewables", "Entity": "China", "Year": 2018}, {"Energy": 5098.22, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2019}, {"Energy": 348.7, "Energy Source": "Nuclear", "Entity": "China", "Year": 2019}, {"Energy": 2014.57, "Energy Source": "Renewables", "Entity": "China", "Year": 2019}, {"Energy": 5184.13, "Energy Source": "Fossil Fuels", "Entity": "China", "Year": 2020}, {"Energy": 366.2, "Energy Source": "Nuclear", "Entity": "China", "Year": 2020}, {"Energy": 2184.94, "Energy Source": "Renewables", "Entity": "China", "Year": 2020}, {"Energy": 475.35, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2000}, {"Energy": 15.77, "Energy Source": "Nuclear", "Entity": "India", "Year": 2000}, {"Energy": 80.27, "Energy Source": "Renewables", "Entity": "India", "Year": 2000}, {"Energy": 491.01, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2001}, {"Energy": 18.89, "Energy Source": "Nuclear", "Entity": "India", "Year": 2001}, {"Energy": 76.19, "Energy Source": "Renewables", "Entity": "India", "Year": 2001}, {"Energy": 517.51, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2002}, {"Energy": 19.35, "Energy Source": "Nuclear", "Entity": "India", "Year": 2002}, {"Energy": 72.78, "Energy Source": "Renewables", "Entity": "India", "Year": 2002}, {"Energy": 545.36, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2003}, {"Energy": 18.14, "Energy Source": "Nuclear", "Entity": "India", "Year": 2003}, {"Energy": 74.63, "Energy Source": "Renewables", "Entity": "India", "Year": 2003}, {"Energy": 567.86, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2004}, {"Energy": 21.26, "Energy Source": "Nuclear", "Entity": "India", "Year": 2004}, {"Energy": 109.2, "Energy Source": "Renewables", "Entity": "India", "Year": 2004}, {"Energy": 579.32, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2005}, {"Energy": 17.73, "Energy Source": "Nuclear", "Entity": "India", "Year": 2005}, {"Energy": 107.47, "Energy Source": "Renewables", "Entity": "India", "Year": 2005}, {"Energy": 599.24, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2006}, {"Energy": 17.63, "Energy Source": "Nuclear", "Entity": "India", "Year": 2006}, {"Energy": 127.56, "Energy Source": "Renewables", "Entity": "India", "Year": 2006}, {"Energy": 636.68, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2007}, {"Energy": 17.83, "Energy Source": "Nuclear", "Entity": "India", "Year": 2007}, {"Energy": 141.75, "Energy Source": "Renewables", "Entity": "India", "Year": 2007}, {"Energy": 674.27, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2008}, {"Energy": 15.23, "Energy Source": "Nuclear", "Entity": "India", "Year": 2008}, {"Energy": 138.91, "Energy Source": "Renewables", "Entity": "India", "Year": 2008}, {"Energy": 728.56, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2009}, {"Energy": 16.82, "Energy Source": "Nuclear", "Entity": "India", "Year": 2009}, {"Energy": 134.33, "Energy Source": "Renewables", "Entity": "India", "Year": 2009}, {"Energy": 771.78, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2010}, {"Energy": 23.08, "Energy Source": "Nuclear", "Entity": "India", "Year": 2010}, {"Energy": 142.61, "Energy Source": "Renewables", "Entity": "India", "Year": 2010}, {"Energy": 828.16, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2011}, {"Energy": 32.22, "Energy Source": "Nuclear", "Entity": "India", "Year": 2011}, {"Energy": 173.62, "Energy Source": "Renewables", "Entity": "India", "Year": 2011}, {"Energy": 893.45, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2012}, {"Energy": 33.14, "Energy Source": "Nuclear", "Entity": "India", "Year": 2012}, {"Energy": 165.25, "Energy Source": "Renewables", "Entity": "India", "Year": 2012}, {"Energy": 924.93, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2013}, {"Energy": 33.31, "Energy Source": "Nuclear", "Entity": "India", "Year": 2013}, {"Energy": 187.9, "Energy Source": "Renewables", "Entity": "India", "Year": 2013}, {"Energy": 1025.29, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2014}, {"Energy": 34.69, "Energy Source": "Nuclear", "Entity": "India", "Year": 2014}, {"Energy": 202.04, "Energy Source": "Renewables", "Entity": "India", "Year": 2014}, {"Energy": 1080.44, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2015}, {"Energy": 38.31, "Energy Source": "Nuclear", "Entity": "India", "Year": 2015}, {"Energy": 203.21, "Energy Source": "Renewables", "Entity": "India", "Year": 2015}, {"Energy": 1155.52, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2016}, {"Energy": 37.9, "Energy Source": "Nuclear", "Entity": "India", "Year": 2016}, {"Energy": 208.21, "Energy Source": "Renewables", "Entity": "India", "Year": 2016}, {"Energy": 1198.85, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2017}, {"Energy": 37.41, "Energy Source": "Nuclear", "Entity": "India", "Year": 2017}, {"Energy": 234.9, "Energy Source": "Renewables", "Entity": "India", "Year": 2017}, {"Energy": 1276.32, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2018}, {"Energy": 39.05, "Energy Source": "Nuclear", "Entity": "India", "Year": 2018}, {"Energy": 263.61, "Energy Source": "Renewables", "Entity": "India", "Year": 2018}, {"Energy": 1273.59, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2019}, {"Energy": 45.16, "Energy Source": "Nuclear", "Entity": "India", "Year": 2019}, {"Energy": 303.16, "Energy Source": "Renewables", "Entity": "India", "Year": 2019}, {"Energy": 1202.34, "Energy Source": "Fossil Fuels", "Entity": "India", "Year": 2020}, {"Energy": 44.61, "Energy Source": "Nuclear", "Entity": "India", "Year": 2020}, {"Energy": 315.76, "Energy Source": "Renewables", "Entity": "India", "Year": 2020}, {"Energy": 2697.28, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2000}, {"Energy": 753.89, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2000}, {"Energy": 350.93, "Energy Source": "Renewables", "Entity": "United States", "Year": 2000}, {"Energy": 2678.68, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2001}, {"Energy": 768.83, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2001}, {"Energy": 280.06, "Energy Source": "Renewables", "Entity": "United States", "Year": 2001}, {"Energy": 2727.83, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2002}, {"Energy": 780.06, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2002}, {"Energy": 336.34, "Energy Source": "Renewables", "Entity": "United States", "Year": 2002}, {"Energy": 2756.03, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2003}, {"Energy": 763.73, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2003}, {"Energy": 349.18, "Energy Source": "Renewables", "Entity": "United States", "Year": 2003}, {"Energy": 2818.28, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2004}, {"Energy": 788.53, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2004}, {"Energy": 345.14, "Energy Source": "Renewables", "Entity": "United States", "Year": 2004}, {"Energy": 2899.96, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2005}, {"Energy": 781.99, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2005}, {"Energy": 353.04, "Energy Source": "Renewables", "Entity": "United States", "Year": 2005}, {"Energy": 2878.56, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2006}, {"Energy": 787.22, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2006}, {"Energy": 381.16, "Energy Source": "Renewables", "Entity": "United States", "Year": 2006}, {"Energy": 2988.24, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2007}, {"Energy": 806.42, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2007}, {"Energy": 347.91, "Energy Source": "Renewables", "Entity": "United States", "Year": 2007}, {"Energy": 2924.21, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2008}, {"Energy": 806.21, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2008}, {"Energy": 377.11, "Energy Source": "Renewables", "Entity": "United States", "Year": 2008}, {"Energy": 2725.41, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2009}, {"Energy": 798.85, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2009}, {"Energy": 415.56, "Energy Source": "Renewables", "Entity": "United States", "Year": 2009}, {"Energy": 2882.49, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2010}, {"Energy": 806.97, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2010}, {"Energy": 424.48, "Energy Source": "Renewables", "Entity": "United States", "Year": 2010}, {"Energy": 2788.93, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2011}, {"Energy": 790.2, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2011}, {"Energy": 509.74, "Energy Source": "Renewables", "Entity": "United States", "Year": 2011}, {"Energy": 2779.02, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2012}, {"Energy": 769.33, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2012}, {"Energy": 492.32, "Energy Source": "Renewables", "Entity": "United States", "Year": 2012}, {"Energy": 2746.21, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2013}, {"Energy": 789.02, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2013}, {"Energy": 520.38, "Energy Source": "Renewables", "Entity": "United States", "Year": 2013}, {"Energy": 2752.01, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2014}, {"Energy": 797.17, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2014}, {"Energy": 546.83, "Energy Source": "Renewables", "Entity": "United States", "Year": 2014}, {"Energy": 2730.32, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2015}, {"Energy": 797.18, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2015}, {"Energy": 556.49, "Energy Source": "Renewables", "Entity": "United States", "Year": 2015}, {"Energy": 2656.96, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2016}, {"Energy": 805.69, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2016}, {"Energy": 624.91, "Energy Source": "Renewables", "Entity": "United States", "Year": 2016}, {"Energy": 2540.17, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2017}, {"Energy": 804.95, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2017}, {"Energy": 707.19, "Energy Source": "Renewables", "Entity": "United States", "Year": 2017}, {"Energy": 2661.3, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2018}, {"Energy": 807.08, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2018}, {"Energy": 733.17, "Energy Source": "Renewables", "Entity": "United States", "Year": 2018}, {"Energy": 2588.21, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2019}, {"Energy": 809.41, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2019}, {"Energy": 760.76, "Energy Source": "Renewables", "Entity": "United States", "Year": 2019}, {"Energy": 2431.9, "Energy Source": "Fossil Fuels", "Entity": "United States", "Year": 2020}, {"Energy": 789.88, "Energy Source": "Nuclear", "Entity": "United States", "Year": 2020}, {"Energy": 821.4, "Energy Source": "Renewables", "Entity": "United States", "Year": 2020}], "metadata": {"Energy": {"type": "number", "semanticType": "Number"}, "Energy Source": {"type": "string", "semanticType": "String", "levels": ["Fossil Fuels", "Nuclear", "Renewables"]}, "Entity": {"type": "string", "semanticType": "Location"}, "Year": {"type": "number", "semanticType": "Year"}}, "derive": {"code": "\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total CO2 emissions by country across all years\n total_co2_by_country = df_energy.groupby('Entity')['Value_co2_emissions_kt_by_country'].sum().reset_index()\n \n # Get top 3 CO2 emitting countries\n top3_countries = total_co2_by_country.nlargest(3, 'Value_co2_emissions_kt_by_country')['Entity'].tolist()\n \n # Filter data for top 3 countries\n df_top3 = df_energy[df_energy['Entity'].isin(top3_countries)].copy()\n \n # Select relevant columns and rename for clarity\n df_top3 = df_top3[['Year', 'Entity', 'Electricity from fossil fuels (TWh)', \n 'Electricity from nuclear (TWh)', 'Electricity from renewables (TWh)']].copy()\n \n df_top3.columns = ['Year', 'Entity', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n df_top3,\n id_vars=['Year', 'Entity'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Entity, Year, and Energy Source\n transformed_df = transformed_df.sort_values(['Entity', 'Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n", "source": ["global-energy-20-small.csv"], "dialog": [{"content": "You are a data scientist to help user to transform data that will be used for visualization.\nThe user will provide you information about what data would be needed, and your job is to create a python function based on the input data summary, transformation instruction and expected fields.\nThe users' instruction includes \"chart_type\" and \"chart_encodings\" that describe the visualization they want, and natural language instructions \"goal\" that describe what data is needed.\n\n**Important:**\n- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.\n- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.\n- If above issue occurs, generate columns with np.nan.\n\nConcretely, you should first refine users' goal and then create a python function in the output section based off the [CONTEXT] and [GOAL]:\n\n 1. First, refine users' [GOAL]. The main objective in this step is to check if \"chart_type\" and \"chart_encodings\" provided by the user are sufficient to achieve their \"goal\". Concretely:\n - based on the user's \"goal\" and \"chart_type\" and \"chart_encodings\", elaborate the goal into a \"detailed_instruction\".\n - \"display_instruction\" is a short verb phrase describing the users' goal. \n - it would be a short verbal description of user intent as a verb phrase (<12 words).\n - generate it based on detailed_instruction and the suggested chart_type and chart_encodings, but don't need to mention the chart details.\n - should capture key computation ideas: by reading the display, the user can understand the purpose and what's derived from the data.\n - if the user specification follows up the previous instruction, the 'display_instruction' should only describe how it builds up the previous instruction without repeating information from previous steps.\n - the phrase can be presented in different styles, e.g., question (what's xxx), instruction (show xxx), description, etc.\n - if you mention column names from the input or the output data, highlight the text in **bold**.\n * the column can either be a column in the input data, or a new column that will be computed in the output data.\n * the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned \"average score\" in the text while the column to be computed is \"Avg_Score\", you should still highlight \"**average score**\" in the text.\n - determine \"output_fields\", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.\n - then decide \"chart_encodings\", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized, \n - the \"chart_encodings\" should be created to support the user's \"chart_type\".\n - first, determine whether the user has provided sufficient fields in \"chart_encodings\" that are needed to achieve their goal:\n - if the user's \"chart_encodings\" are sufficient, simply copy it.\n - if the user didn't provide sufficient fields in \"chart_encodings\", add missing fields in \"chart_encodings\" (ordered them based on whether the field will be used in x,y axes or legends);\n - \"chart_encodings\" should only include fields that will be visualized (do not include other intermediate fields from \"output_fields\") \n - when adding new fields to \"chart_encodings\", be efficient and add only a minimal number of fields that are needed to achive the user's goal. \n - generally, the total number of fields in \"chart_encodings\" should be no more than 3 for x,y,legend.\n - if the user's \"chart_encodings\" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.\n - sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final \"chart_encodings\"\n - e.g., they may mention \"use B metric instead\" while A metric is in provided fields, in this case, you should update \"chart_encodings\" to update A metric with B metric.\n - guide on statistical analysis:\n - when the user asks for forecasting or regression analysis, you should consider the following:\n - the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column \"is_predicted\" that is a boolean field.\n - i.e., if the user ask for forecasting based on two columns T and Y, the output should be three columns: T, Y, is_predicted, where\n - T, Y columns contain BOTH original values from the data and predicted values from the data.\n - is_predicted is a boolean field to indicate whether the x, y pairs are original values from the data or predicted / regression values from the data.\n - the recommended chart should be line chart (time series) or scatter plot (quantitative x, y)\n - if the user asks for forecasting, it's good to include predicted x, y pairs for both x in the original data and future x values (i.e., combine regression and forecasting results)\n - in this case, is_predicted should be of three values 'original', 'regression', 'forecasting'\n - when the user asks for clustering:\n - the output should be a long format table where actual x, y pairs with a third column \"cluster_id\" that indicates the cluster id of the data point.\n - the recommended chart should be scatter plot (quantitative x, y)\n \n Prepare the result in the following json format:\n\n```\n{\n \"detailed_instruction\": \"...\" // string, elaborate user instruction with details if the user\n \"display_instruction\": \"...\" // string, the short verb phrase describing the users' goal.\n \"output_fields\": [...] // string[], describe the desired output fields that the output data should have based on the user's goal, it's a good idea to preserve intermediate fields here (i.e., the goal of transformed data)\n \"chart_encodings\": {\n \"x\": \"\",\n \"y\": \"\",\n \"color\": \"\",\n \"size\": \"\",\n \"opacity\": \"\",\n \"facet\": \"\",\n ... // other visualization channels user used\n } // object: map visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of \"output_fields\" that will be visualized.\n \"reason\": \"...\" // string, explain why this refinement is made\n}\n```\n\n 2. Then, write a python function based on the refined goal, the function input is a dataframe \"df\" (or multiple dataframes based on tables presented in the [CONTEXT] section) and the output is the transformed dataframe \"transformed_df\". \"transformed_df\" should contain all \"output_fields\" from the refined goal.\nThe python function must follow the template provided in [TEMPLATE], do not import any other libraries or modify function name. The function should be as simple as possible and easily readable.\nIf there is no data transformation needed based on \"output_fields\", the transformation function can simply \"return df\".\n\n[TEMPLATE]\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\nfrom sklearn import ... # import necessary libraries from sklearn if needed\n\ndef transform_data(df1, df2, ...): \n # complete the template here\n return transformed_df\n```\n\nnote: \n- if the user provided one table, then it should be `def transform_data(df1)`, if the user provided multiple tables, then it should be `def transform_data(df1, df2, ...)` and you should consider the join between tables to derive the output.\n- **VERY IMPORTANT** the number of arguments in the function must match the number of tables provided, and the order of arguments must match the order of tables provided.\n- try to use intuitive table names to refer to the input dataframes, for example, if the user provided two tables city and weather, you can use `transform_data(df_city, df_weather)` to refer to the two dataframes, as long as the number and order of the arguments match the number and order of the tables provided.\n- datetime objects handling:\n - if the output field is year, convert it to number, if it is year-month / year-month-day, convert it to string object (e.g., \"2020-01\" / \"2020-01-01\").\n - if the output is time only: convert hour to number if it's just the hour (e.g., 10), but convert hour:min or h:m:s to string object (e.g., \"10:30\", \"10:30:45\")\n - never return datetime object directly, convert it to either number (if it only contains year) or string so it's readable.\n\n 3. The output must only contain a json object representing the refined goal and a python code block representing the transformation code, do not add any extra text explanation.\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5736319.824, 5738290.039, nan, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 61.99, 62.21, 63.02, 63.71\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[GOAL]\n\n{\n \"instruction\": \"compare each countries renewable between 2000 and 2020\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Energy\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Compare renewable energy (Electricity from renewables) for each country between the years 2000 and 2020. Filter the data to include only years 2000 and 2020, and prepare the output with country names, year, and renewable energy values for visualization as a grouped bar chart.\",\n \"display_instruction\": \"Compare **renewable energy** by **country** between **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Electricity from renewables (TWh)\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to compare renewable energy across countries between 2000 and 2020. The output field 'Renewable Energy' mentioned in the original chart_encodings maps to 'Electricity from renewables (TWh)' in the dataset. To create a grouped bar chart comparing these two years, we need to filter the data to only include years 2000 and 2020, and output the Entity (country), Year, and the renewable energy values. The chart_encodings are updated to use the actual column name from the dataset.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n transformed_df = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Select only the required columns\n transformed_df = transformed_df[['Entity', 'Year', 'Electricity from renewables (TWh)']]\n \n # Convert Year to string for better visualization as a categorical variable\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year for better readability\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Electricity from renewables (TWh) Entity Year\n0 17.11 Australia 2000\n1 63.99 Australia 2020\n2 308.77 Brazil 2000\n3 520.01 Brazil 2020\n4 363.70 Canada 2000\n5 429.24 Canada 2020\n6 225.56 China 2000\n7 2184.94 China 2020\n8 67.83 France 2000\n9 125.28 France 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show their renewable percentage instead, and add an entity to show global average\",\n \"chart_type\": \"Grouped Bar Chart\",\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Electricity from renewables (TWh)\",\n \"color\": \"Year\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Calculate the renewable energy percentage (proportion of renewables to total electricity generation from all sources) for each country between 2000 and 2020. Add a 'Global Average' entity that represents the worldwide average renewable percentage for each year. The output should include Entity (with 'Global Average' added), Year, and the renewable percentage.\",\n \"display_instruction\": \"Show **renewable energy percentage** by **country** with **global average** for **2000** and **2020**\",\n \"output_fields\": [\"Entity\", \"Year\", \"Renewable Percentage\"],\n \"chart_encodings\": {\n \"x\": \"Entity\",\n \"y\": \"Renewable Percentage\",\n \"color\": \"Year\"\n },\n \"reason\": \"The user wants to see renewable percentage instead of absolute values, and wants to add a global average entity for comparison. Renewable percentage is calculated as the ratio of renewable energy to total electricity generation (fossil fuels + nuclear + renewables). A 'Global Average' entity needs to be computed by aggregating all countries' data for each year. The y-axis encoding is updated to reflect the new metric 'Renewable Percentage'.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Filter data for years 2000 and 2020\n df_filtered = df_energy[df_energy['Year'].isin([2000, 2020])].copy()\n \n # Calculate total electricity generation\n df_filtered['Total Electricity'] = (\n df_filtered['Electricity from fossil fuels (TWh)'] + \n df_filtered['Electricity from nuclear (TWh)'] + \n df_filtered['Electricity from renewables (TWh)']\n )\n \n # Calculate renewable percentage\n df_filtered['Renewable Percentage'] = (\n df_filtered['Electricity from renewables (TWh)'] / df_filtered['Total Electricity'] * 100\n )\n \n # Select required columns for individual countries\n country_data = df_filtered[['Entity', 'Year', 'Renewable Percentage']].copy()\n \n # Calculate global average for each year\n global_avg = df_filtered.groupby('Year').apply(\n lambda x: pd.Series({\n 'Entity': 'Global Average',\n 'Year': x['Year'].iloc[0],\n 'Renewable Percentage': (\n x['Electricity from renewables (TWh)'].sum() / x['Total Electricity'].sum() * 100\n )\n })\n ).reset_index(drop=True)\n \n # Combine country data with global average\n transformed_df = pd.concat([country_data, global_avg], ignore_index=True)\n \n # Convert Year to string for better visualization\n transformed_df['Year'] = transformed_df['Year'].astype(str)\n \n # Sort by Entity and Year\n transformed_df = transformed_df.sort_values(['Entity', 'Year']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Entity Renewable Percentage Year\n0 Australia 8.634437 2000\n1 Australia 25.503168 2020\n2 Brazil 90.130772 2000\n3 Brazil 84.641177 2020\n4 Canada 61.809592 2000\n5 Canada 68.779644 2020\n6 China 16.639127 2000\n7 China 28.246461 2020\n8 France 12.711769 2000\n9 France 23.761024 2020\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show global energy composition over time\",\n \"chart_type\": \"Custom Area\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Show the global energy composition over time by aggregating electricity generation from all countries for each year, broken down by energy source (fossil fuels, nuclear, and renewables). The output should be in long format with Year, Energy Source, and Energy values to support a stacked area chart visualization.\",\n \"display_instruction\": \"Show global **energy composition** by **energy source** over time\",\n \"output_fields\": [\"Year\", \"Energy Source\", \"Energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n },\n \"reason\": \"The user wants to visualize global energy composition over time, which requires aggregating electricity generation data across all countries for each year and breaking it down by energy source type. The data needs to be transformed into long format where each row represents a year-energy source combination, with the total energy value for that source globally. This follows up from the previous renewable percentage analysis by showing the overall energy mix trends rather than focusing on specific countries or percentages.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Group by Year and sum electricity generation from all countries\n global_energy = df_energy.groupby('Year').agg({\n 'Electricity from fossil fuels (TWh)': 'sum',\n 'Electricity from nuclear (TWh)': 'sum',\n 'Electricity from renewables (TWh)': 'sum'\n }).reset_index()\n \n # Rename columns for clarity\n global_energy.columns = ['Year', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n global_energy,\n id_vars=['Year'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Year and Energy Source\n transformed_df = transformed_df.sort_values(['Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}, {"content": "This is the result from the latest python code:\n\n Energy Energy Source Year\n0 7160.71 Fossil Fuels 2000\n1 1996.65 Nuclear 2000\n2 1742.56 Renewables 2000\n3 7273.89 Fossil Fuels 2001\n4 2037.54 Nuclear 2001\n5 1690.11 Renewables 2001\n6 7621.07 Fossil Fuels 2002\n7 2042.18 Nuclear 2002\n8 1757.63 Renewables 2002\n9 8043.86 Fossil Fuels 2003\n......\n\nUpdate the code above based on the following instruction:\n\n{\n \"followup_instruction\": \"show the composition of top 3 CO2 emitting countries\",\n \"chart_type\": \"Custom Area\",\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\"\n }\n}", "role": "user"}, {"content": "```json\n{\n \"detailed_instruction\": \"Identify the top 3 CO2 emitting countries based on total CO2 emissions across all years, then show the energy composition (fossil fuels, nuclear, and renewables) for each of these countries over time. The output should be in long format with Year, Entity (country), Energy Source, and Energy values to support faceted area charts.\",\n \"display_instruction\": \"Show **energy composition** of **top 3 CO2 emitting countries** over time\",\n \"output_fields\": [\"Year\", \"Entity\", \"Energy Source\", \"Energy\"],\n \"chart_encodings\": {\n \"x\": \"Year\",\n \"y\": \"Energy\",\n \"color\": \"Energy Source\",\n \"facet\": \"Entity\"\n },\n \"reason\": \"The user wants to see the energy composition specifically for the top 3 CO2 emitting countries over time, following up from the global energy composition view. We need to identify which countries have the highest total CO2 emissions, filter the data for those countries, and transform it into long format by energy source. A facet encoding is added to show separate area charts for each of the top 3 countries, allowing comparison of their individual energy compositions over time.\"\n}\n```\n\n```python\nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total CO2 emissions by country across all years\n total_co2_by_country = df_energy.groupby('Entity')['Value_co2_emissions_kt_by_country'].sum().reset_index()\n \n # Get top 3 CO2 emitting countries\n top3_countries = total_co2_by_country.nlargest(3, 'Value_co2_emissions_kt_by_country')['Entity'].tolist()\n \n # Filter data for top 3 countries\n df_top3 = df_energy[df_energy['Entity'].isin(top3_countries)].copy()\n \n # Select relevant columns and rename for clarity\n df_top3 = df_top3[['Year', 'Entity', 'Electricity from fossil fuels (TWh)', \n 'Electricity from nuclear (TWh)', 'Electricity from renewables (TWh)']].copy()\n \n df_top3.columns = ['Year', 'Entity', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n df_top3,\n id_vars=['Year', 'Entity'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Entity, Year, and Energy Source\n transformed_df = transformed_df.sort_values(['Entity', 'Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n```", "role": "assistant"}], "trigger": {"tableId": "table-81", "resultTableId": "table-10", "chart": {"id": "chart-1760739075465", "chartType": "Custom Area", "encodingMap": {"x": {"channel": "x", "bin": false, "fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"channel": "y", "bin": false, "fieldID": "concept-1760738917347"}, "x2": {}, "y2": {"channel": "y2", "bin": false}, "color": {"fieldID": "concept-1760738921927", "sortBy": "[\"Fossil Fuels\",\"Nuclear\",\"Renewables\"]"}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-81", "saved": false, "source": "trigger", "unread": false}, "interaction": [{"from": "user", "to": "datatransform-agent", "role": "instruction", "content": "show the composition of top 3 CO2 emitting countries", "displayContent": "Show **energy composition** of **top 3 CO2 emitting countries** over time"}]}, "explanation": {"agent": "CodeExplanationAgent", "code": "The code performs the following high-level transformations:\n\n1. **Identifies top polluters**: Calculates the total `Value_co2_emissions_kt_by_country` across all years for each `Entity` (country), then selects the **top 3** countries with the highest cumulative CO2 emissions.\n\n2. **Filters the dataset**: Retains only records for the **top 3 CO2-emitting countries** from the original energy data.\n\n3. **Simplifies column structure**: Extracts the relevant energy production columns (`Electricity from fossil fuels (TWh)`, `Electricity from nuclear (TWh)`, `Electricity from renewables (TWh)`) and renames them to **Fossil Fuels**, **Nuclear**, and **Renewables** for clarity.\n\n4. **Reshapes data to long format**: Transforms the data from wide format (separate columns for each energy source) to long format, where each row represents a specific `Year`, `Entity`, and `Energy Source` combination with its corresponding `Energy` production value.\n\n5. **Sorts the output**: Orders the final dataset by `Entity`, `Year`, and `Energy Source` for systematic presentation.", "concepts": [], "dialog": [{"content": "You are a data scientist to help user explain code, \nso that a non-code can clearly understand what the code is doing, you are provided with a summary of the input data, and the transformation code.\n\nYour goal:\n1. You should generate a good itemized explanation of the code so that the reader can understand high-level steps of what the data transformation is doing.\n - Be very concise, and stay at a high-level. The reader doesn't understand code and does not want to learn exactly what the code is doing. They just want to learn what have been done from a logical level.\n - The explanation should be a markdown string that is a list of bullet points (with new lines), highlight constants, data fields, and important verbs.\n2. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.\n - provide a declarative definition that explains the new field, use a mathematical notation if applicable.\n - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)\n - *DO NOT* explain trivial new fields like \"Decade\" or \"Avg_Rating\", \"US_Sales\" that are self-explanatory.\n - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)\n - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:\n - Inline math: `\\( ... \\)` for formulas within text\n - Block math: `\\[ ... \\]` for standalone formulas\n - Examples: `\\( \\frac{\\text{Revenue}}{\\text{Cost}} \\)` for ratios, `\\[ \\text{Score} = \\text{Rating} \\times \\text{Worldwide\\_Gross} \\]` for formulas\n - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\\_`\n - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader. \n Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.\n3. If there are multiple fields that have the similar computation, you can explain them together in one explanation.\n - in \"field\", you can provide a list of fields in format of \"field1, field2, ...\"\n - in \"explanation\", you can provide a single explanation for the computation of the fields.\n - for example, if you have fields like \"Norm_Rating\", \"Norm_Gross\", \"Critical_Commercial_Score\", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.\n4. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named \"Statistical Analysis\" in the [CONCEPTS EXPLANATION] section.\n - explain how you model the data, which fields are used, how data processing is done, and what models are used.\n - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.\n \nThe focus is to explain how new fields are computed, don't generate explanation for low-level actions like \"return\", \"load data\" etc. \n\nProvide the result in the following two sections:\n - first section is the code explanation that should be a markdown block explaining the code, in the [CODE EXPLANATION] section.\n - remember to highlight constants, data fields, and important verbs in the code explanation.\n - second section is the concepts explanation that should be a json block (start with ```json) in the [CONCEPTS EXPLANATION] section.\n\n[CODE EXPLANATION]\n\n...(explanation of the code)\n\n[CONCEPTS EXPLANATION]\n\n```json\n[\n {\n \"field\": \"...\",\n \"explanation\": \"...\"\n }\n]\n\n```\n", "role": "system"}, {"content": "[CONTEXT]\n\nHere are our datasets, here are their summaries and samples:\n\n# table1 (global_energy_20_small_csv)\n\n## fields\n\t*Year -- type: int64, values: 2000, 2001, 2002, ..., 2017, 2018, 2019, 2020\n\t*Entity -- type: object, values: Australia, Brazil, Canada, ..., Thailand, Ukraine, United Kingdom, United States\n\t*Value_co2_emissions_kt_by_country -- type: float64, values: 117440.0, 146139.9994, 158029.9988, ..., 5593029.785, 5736319.824, 5738290.039, 9861099.609\n\t*Electricity from fossil fuels (TWh) -- type: float64, values: 28.87, 31.62, 33.5, ..., 4643.1, 4990.28, 5098.22, 5184.13\n\t*Electricity from nuclear (TWh) -- type: float64, values: 0.0, 3.24, 4.94, ..., 62.21, 63.02, 63.71, 439.73\n\t*Electricity from renewables (TWh) -- type: float64, values: 0.0, 0.01, 0.03, ..., 1667.06, 1835.32, 2014.57, 2184.94\n\n## sample\n Year Entity Value_co2_emissions_kt_by_country Electricity from fossil fuels (TWh) Electricity from nuclear (TWh) Electricity from renewables (TWh)\n0 2000 Australia 339450.0000 181.05 0 17.11\n1 2001 Australia 345640.0000 194.33 0 17.40\n2 2002 Australia 353369.9951 197.29 0 17.35\n3 2003 Australia 352579.9866 195.13 0 18.50\n4 2004 Australia 365809.9976 203.66 0 19.41\n......\n\n\n\n\n[CODE]\n\nhere is the transformation code: \nimport pandas as pd\nimport collections\nimport numpy as np\n\ndef transform_data(df_energy):\n # Calculate total CO2 emissions by country across all years\n total_co2_by_country = df_energy.groupby('Entity')['Value_co2_emissions_kt_by_country'].sum().reset_index()\n \n # Get top 3 CO2 emitting countries\n top3_countries = total_co2_by_country.nlargest(3, 'Value_co2_emissions_kt_by_country')['Entity'].tolist()\n \n # Filter data for top 3 countries\n df_top3 = df_energy[df_energy['Entity'].isin(top3_countries)].copy()\n \n # Select relevant columns and rename for clarity\n df_top3 = df_top3[['Year', 'Entity', 'Electricity from fossil fuels (TWh)', \n 'Electricity from nuclear (TWh)', 'Electricity from renewables (TWh)']].copy()\n \n df_top3.columns = ['Year', 'Entity', 'Fossil Fuels', 'Nuclear', 'Renewables']\n \n # Transform to long format\n transformed_df = pd.melt(\n df_top3,\n id_vars=['Year', 'Entity'],\n value_vars=['Fossil Fuels', 'Nuclear', 'Renewables'],\n var_name='Energy Source',\n value_name='Energy'\n )\n \n # Sort by Entity, Year, and Energy Source\n transformed_df = transformed_df.sort_values(['Entity', 'Year', 'Energy Source']).reset_index(drop=True)\n \n return transformed_df\n\n\n[EXPLANATION]\n", "role": "user"}, {"content": "[CODE EXPLANATION]\n\nThe code performs the following high-level transformations:\n\n1. **Identifies top polluters**: Calculates the total `Value_co2_emissions_kt_by_country` across all years for each `Entity` (country), then selects the **top 3** countries with the highest cumulative CO2 emissions.\n\n2. **Filters the dataset**: Retains only records for the **top 3 CO2-emitting countries** from the original energy data.\n\n3. **Simplifies column structure**: Extracts the relevant energy production columns (`Electricity from fossil fuels (TWh)`, `Electricity from nuclear (TWh)`, `Electricity from renewables (TWh)`) and renames them to **Fossil Fuels**, **Nuclear**, and **Renewables** for clarity.\n\n4. **Reshapes data to long format**: Transforms the data from wide format (separate columns for each energy source) to long format, where each row represents a specific `Year`, `Entity`, and `Energy Source` combination with its corresponding `Energy` production value.\n\n5. **Sorts the output**: Orders the final dataset by `Entity`, `Year`, and `Energy Source` for systematic presentation.\n\n[CONCEPTS EXPLANATION]\n\n```json\n[]\n```", "role": "assistant"}], "status": "ok"}, "status": "completed"}, "anchored": false, "attachedMetadata": ""}], "charts": [{"id": "chart-1760739084455", "chartType": "Custom Area", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-1760738917347"}, "x2": {}, "y2": {"channel": "y2", "bin": false}, "color": {"fieldID": "concept-1760738921927"}, "column": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-10", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760739021201", "chartType": "Custom Area", "encodingMap": {"x": {"channel": "x", "bin": false, "fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"channel": "y", "bin": false, "fieldID": "concept-1760738917347"}, "x2": {}, "y2": {"channel": "y2", "bin": false}, "color": {"fieldID": "concept-1760738921927", "sortBy": "[\"Fossil Fuels\",\"Nuclear\",\"Renewables\"]"}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-81", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738819387", "chartType": "Grouped Bar Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "y": {"fieldID": "concept-Renewable Percentage-1760738820889"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}, "group": {"fieldID": "original--global-energy-20-small.csv--Year"}}, "tableRef": "table-27", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738770100", "chartType": "Grouped Bar Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "y": {"fieldID": "original--global-energy-20-small.csv--Electricity from renewables (TWh)"}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}, "group": {"fieldID": "original--global-energy-20-small.csv--Year"}}, "tableRef": "table-97", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738436615", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year", "sortOrder": "ascending"}, "y": {"fieldID": "concept-rank-1760738444550", "sortOrder": "descending"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-78", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738423852", "chartType": "Line Chart", "config": {"showPoints": true}, "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-renewable_percentage-1760738424337"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "column": {}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-45", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738400970", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "concept-1760738385163"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {"fieldID": "concept-1760738389404", "sortBy": "[\"fossil fuels\",\"nuclear\",\"renewables\"]"}, "row": {"channel": "row", "bin": false}}, "tableRef": "table-82", "saved": false, "source": "user", "unread": false}, {"id": "chart-1760738355655", "chartType": "Line Chart", "encodingMap": {"x": {"fieldID": "original--global-energy-20-small.csv--Year"}, "y": {"fieldID": "original--global-energy-20-small.csv--Value_co2_emissions_kt_by_country"}, "color": {"fieldID": "original--global-energy-20-small.csv--Entity"}, "opacity": {"channel": "opacity", "bin": false}, "column": {"channel": "column", "bin": false}, "row": {"channel": "row", "bin": false}}, "tableRef": "global-energy-20-small.csv", "saved": false, "source": "user", "unread": false}], "conceptShelfItems": [{"id": "concept-1760738921927", "name": "Energy Source", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "concept-1760738917347", "name": "Energy", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "concept-Renewable Percentage-1760738820889", "name": "Renewable Percentage", "type": "auto", "description": "", "source": "custom", "tableRef": "custom", "temporary": true}, {"id": "concept-1760738743125", "name": "Renewable Energy", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "concept-rank-1760738444550", "name": "rank", "type": "auto", "description": "", "source": "custom", "tableRef": "custom", "temporary": true}, {"id": "concept-renewable_percentage-1760738424337", "name": "renewable_percentage", "type": "auto", "description": "", "source": "custom", "tableRef": "custom", "temporary": true}, {"id": "concept-1760738389404", "name": "source", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "concept-1760738385163", "name": "energy", "type": "auto", "description": "", "source": "custom", "tableRef": "custom"}, {"id": "original--global-energy-20-small.csv--Year", "name": "Year", "type": "integer", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Entity", "name": "Entity", "type": "string", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Value_co2_emissions_kt_by_country", "name": "Value_co2_emissions_kt_by_country", "type": "number", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Electricity from fossil fuels (TWh)", "name": "Electricity from fossil fuels (TWh)", "type": "number", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Electricity from nuclear (TWh)", "name": "Electricity from nuclear (TWh)", "type": "number", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}, {"id": "original--global-energy-20-small.csv--Electricity from renewables (TWh)", "name": "Electricity from renewables (TWh)", "type": "number", "source": "original", "description": "", "tableRef": "global-energy-20-small.csv"}], "messages": [{"timestamp": 1760831081885, "type": "success", "component": "data formulator", "value": "Successfully loaded Global Energy"}], "displayedMessageIdx": 0, "viewMode": "report", "chartSynthesisInProgress": [], "config": {"formulateTimeoutSeconds": 60, "maxRepairAttempts": 1, "defaultChartWidth": 300, "defaultChartHeight": 300}, "dataCleanBlocks": [], "cleanInProgress": false, "generatedReports": [{"id": "report-1760831156182-8277", "content": "# Global Renewable Energy Shift: 2000 to 2020\n\nBetween 2000 and 2020, the world witnessed a notable transformation in renewable energy adoption. Global renewable electricity nearly doubled from 16% to 29% of total generation, signaling meaningful progress in the energy transition.\n\n[IMAGE(chart-1760738819387)]\n\nThe data reveals striking regional variations. Brazil maintained renewable leadership above 84%, while countries like Australia, Germany, and Italy dramatically expanded their renewable capacity—Australia tripling from 9% to 26%. However, some nations like Mexico experienced declining renewable shares, highlighting uneven progress across different energy systems.\n\n**In summary**, while the 20-year period shows encouraging momentum toward cleaner energy, the pace and direction vary significantly by country, suggesting that achieving global renewable energy goals will require sustained, coordinated efforts tailored to each nation's unique energy landscape and policy environment.", "style": "short note", "selectedChartIds": ["chart-1760738819387"], "createdAt": 1760831163718, "status": "completed", "title": "Global Renewable Energy Shift: 2000 to 2020", "anchorChartId": "chart-1760738819387"}, {"id": "report-1760831130105-4063", "content": "# The Global Renewable Energy Revolution: Two Decades of Transformation\n\nThe world's energy landscape has undergone a remarkable transformation between 2000 and 2020, with renewable electricity generation emerging as a critical component of the global energy mix. This shift reflects both technological advancement and growing commitment to sustainable energy solutions.\n\n[IMAGE(chart-1760738770100)]\n\nLooking at renewable energy adoption across major economies, the growth has been nothing short of extraordinary. China leads the pack with a staggering increase from 225.56 TWh in 2000 to 2,184.94 TWh in 2020—nearly a tenfold expansion. The United States more than doubled its renewable output from 335.45 TWh to 821.40 TWh, while Brazil grew from 308.77 TWh to 520.01 TWh. Notably, countries like Australia, India, and Germany also demonstrated significant gains, with Australia jumping from just 17.11 TWh to 63.99 TWh during this period.\n\n[IMAGE(chart-1760739084455)]\n\nWhen examining the energy portfolios of the three largest CO2 emitters—China, India, and the United States—a complex picture emerges. While China's total energy consumption has grown exponentially, with fossil fuels still dominating, the renewable sector (shown in red) has expanded substantially. The United States shows a more stable total energy consumption, with renewables gradually claiming a larger share. India's energy growth, though significant, remains heavily reliant on fossil fuels, though renewable adoption is accelerating.\n\n**In summary**, the past two decades reveal a global energy transition in progress. While renewable energy has achieved impressive growth worldwide, fossil fuels continue to dominate electricity generation in major economies. Key questions remain: Can this momentum accelerate sufficiently to meet climate goals? What policies will drive faster renewable adoption in emerging economies?", "style": "blog post", "selectedChartIds": ["chart-1760739084455", "chart-1760738770100"], "createdAt": 1760831142289, "status": "completed", "title": "The Global Renewable Energy Revolution: Two Decades of Transformation", "anchorChartId": "chart-1760739084455"}, {"id": "report-1760831094231-2424", "content": "# Global Renewable Energy: A Tale of Leaders and Laggards\n\nThe global energy landscape has undergone significant transformation over the past two decades, with renewable energy emerging as a critical player in the electricity mix. Analyzing data from 21 major economies between 2000 and 2020 reveals striking disparities in how nations have embraced clean energy alternatives.\n\n[IMAGE(chart-1760738423852)]\n\nThe first visualization reveals a fascinating divergence in renewable energy adoption. **Brazil** stands out as a consistent leader, maintaining renewable electricity percentages between 75-90% throughout the entire period, thanks largely to its robust hydroelectric infrastructure. **Canada** follows a similar trajectory, steadily increasing from about 60% to nearly 70% by 2020. Meanwhile, **Germany, Spain, Italy, and the United Kingdom** show remarkable growth trajectories, climbing from under 20% in the early 2000s to over 40% by 2020—demonstrating that nations can dramatically reshape their energy portfolios within two decades.\n\nOn the opposite end of the spectrum, **South Africa** remains nearly flat at the bottom, showing minimal renewable adoption despite global trends. **Saudi Arabia** and **Poland** also lag significantly, though both show modest upticks in recent years.\n\n[IMAGE(chart-1760738436615)]\n\nThe ranking chart illustrates the competitive dynamics of renewable energy leadership. **Brazil and Canada** maintain their dominance at ranks 1-2 throughout most years, while European nations like **Germany, Spain, and the UK** engage in a dynamic competition for the 3rd-5th positions, particularly after 2010. The volatility in middle rankings reflects the rapid changes in energy policy and investment across different nations, with countries like **China** climbing from lower ranks to break into the top 7 by 2020.\n\n**In summary**, the data reveals a bifurcated global energy transition: a group of progressive nations have successfully scaled renewable electricity to 40-90% of their mix, while others remain heavily dependent on fossil fuels. These patterns suggest that political will, natural resource endowment, and infrastructure investment are key determinants of renewable energy success. Important follow-up questions include: What policy mechanisms enabled top performers to achieve such high renewable percentages? Can lagging nations replicate these successes, or do geographic and economic constraints create insurmountable barriers?", "style": "blog post", "selectedChartIds": ["chart-1760738423852", "chart-1760738436615"], "createdAt": 1760831110064, "status": "completed", "title": "Global Renewable Energy: A Tale of Leaders and Laggards", "anchorChartId": "chart-1760738423852"}], "currentReport": {"id": "report-1760750575650-2619", "content": "# Hollywood's Billion-Dollar Hitmakers\n\n*Avatar* stands alone—earning over $2.5B in profit, dwarfing all competition. Action and Adventure films dominate the most profitable titles, with franchises like *Jurassic Park*, *The Dark Knight*, and *Lord of the Rings* proving blockbuster formulas work.\n\n\n\nSteven Spielberg leads all directors with $7.2B in total profit across his career, showcasing remarkable consistency with hits spanning decades—from *Jurassic Park* to *E.T.* His nearest competitors trail by billions, underlining his unmatched commercial impact.\n\n\n\n**In summary**, mega-budget Action and Adventure films generate extraordinary returns when they succeed, and a handful of elite directors—led by Spielberg—have mastered the formula for sustained box office dominance.", "style": "short note", "selectedChartIds": ["chart-1760743347871", "chart-1760743768741"], "chartImages": {}, "createdAt": 1760750584189, "title": "Report - 10/17/2025"}, "activeChallenges": [], "_persist": {"version": -1, "rehydrated": true}, "draftNodes": [], "focusedId": {"type": "report", "reportId": "report-1760831156182-8277"}}
\ No newline at end of file
diff --git a/py-src/data_formulator/agent_config.py b/py-src/data_formulator/agent_config.py
new file mode 100644
index 00000000..bec4c670
--- /dev/null
+++ b/py-src/data_formulator/agent_config.py
@@ -0,0 +1,152 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+"""
+Single source of truth for per-agent LLM call configuration.
+
+Edit values here to tune latency vs. quality for each agent.
+
+Per-agent overrides can also be set at runtime via environment variables:
+
+ DF_REASONING_EFFORT_DATA_TRANSFORM=medium
+ DF_REASONING_EFFORT_REPORT_GEN=high
+
+Tiers
+-----
+- ``"minimal"`` — fastest. Honoured natively only on the OpenAI GPT-5
+ base/mini/nano/5.x family (``gpt-5``, ``gpt-5-mini``, ``gpt-5-nano``,
+ ``gpt-5.1``, ...). On the GPT-5 ``codex`` / ``pro`` variants
+ :func:`reasoning_effort_for` maps it to ``"none"`` (their lightest
+ supported tier). On every other reasoning model (o-series, Claude
+ extended-thinking, Gemini, ...) it is downgraded to ``"low"``.
+- ``"none"`` — only accepted by GPT-5 ``codex`` / ``pro``. Downgraded to
+ ``"low"`` elsewhere.
+- ``"low" | "medium" | "high"`` — portable across all reasoning providers via
+ LiteLLM's normalisation
+ (https://docs.litellm.ai/docs/reasoning_content).
+
+Models that don't support reasoning at all silently drop the parameter
+because the client is invoked with ``drop_params=True``.
+"""
+
+from __future__ import annotations
+
+import os
+from typing import Literal
+
+ReasoningEffort = Literal["none", "minimal", "low", "medium", "high"]
+
+# ---------------------------------------------------------------------------
+# Per-agent reasoning effort
+# ---------------------------------------------------------------------------
+#
+# Pick the lowest tier that produces acceptable quality. Heavy code-generation
+# and multi-step agents stay at ``"low"``; trivial single-turn extractors and
+# classifiers run at ``"minimal"`` (GPT-5) / ``"low"`` (everything else).
+
+AGENT_REASONING_EFFORT: dict[str, ReasoningEffort] = {
+ # ── Heavy: code-gen, multi-step, tool-using ─────────────────────────────
+ "data_transform": "low", # generates Python transform scripts
+ "data_rec": "low", # chart / transformation recommendation
+ "data_agent": "low", # multi-step exploration agent
+ "report_gen": "low", # narrative + inspect/embed tools
+ "interactive_explore": "low", # exploration idea agent
+ "data_loading_chat": "low", # conversational data loading w/ tools
+
+ # ── Light: single-turn extractors / classifiers / formatters ────────────
+ "data_load": "minimal", # one-shot type inference
+ "data_clean": "minimal", # extract tables from text
+ "experience_distill": "minimal", # summarise an analysis context
+ "chart_insight": "minimal", # title + 1–3 takeaways from a chart
+ "chart_restyle": "minimal", # apply style edits to a Vega-Lite spec
+ "code_explanation": "minimal", # describe derived fields
+ "sort_data": "minimal", # natural-order sort a small list
+ "simple": "minimal", # nl_to_filter / workspace_name / intent
+}
+
+DEFAULT_REASONING_EFFORT: ReasoningEffort = "low"
+
+_VALID_TIERS: frozenset[str] = frozenset(("none", "minimal", "low", "medium", "high"))
+
+
+def get_reasoning_effort(agent_id: str | None) -> ReasoningEffort:
+ """Return the *configured* tier for ``agent_id``.
+
+ Resolution order:
+ 1. ``DF_REASONING_EFFORT_`` env var
+ 2. ``AGENT_REASONING_EFFORT[agent_id]``
+ 3. ``DEFAULT_REASONING_EFFORT``
+
+ Note: this does **not** consider the target model. Use
+ :func:`reasoning_effort_for` at call time to also apply the
+ GPT-5-only ``"minimal"`` gating.
+ """
+ if agent_id:
+ env_key = f"DF_REASONING_EFFORT_{agent_id.upper()}"
+ env_val = (os.environ.get(env_key) or "").strip().lower()
+ if env_val in _VALID_TIERS:
+ return env_val # type: ignore[return-value]
+ if agent_id in AGENT_REASONING_EFFORT:
+ return AGENT_REASONING_EFFORT[agent_id]
+ return DEFAULT_REASONING_EFFORT
+
+
+def _supports_minimal(model: str | None) -> bool:
+ """``"minimal"`` is only accepted by a subset of OpenAI GPT-5 chat models.
+
+ Supported (per OpenAI API):
+ ``gpt-5``, ``gpt-5-mini``, ``gpt-5-nano``, ``gpt-5.1``, ``gpt-5.4``,
+ and future GPT-5.x sub-versions of those base variants.
+
+ NOT supported (these reject ``"minimal"`` but accept ``"none"`` / ``xhigh``
+ instead): ``gpt-5-codex``, ``gpt-5-pro``.
+
+ Provider prefixes such as ``openai/gpt-5-mini``, ``azure/gpt-5``,
+ ``openai/responses/gpt-5.4`` are all covered by the substring check.
+ """
+ if not model:
+ return False
+ m = model.lower()
+ if "gpt-5" not in m:
+ return False
+ if "codex" in m or "-pro" in m or "/pro" in m:
+ return False
+ return True
+
+
+def _supports_none(model: str | None) -> bool:
+ """``"none"`` is the lightest tier on the GPT-5 ``codex`` / ``pro`` chat
+ models (which reject ``"minimal"``). Other providers (Claude, Gemini,
+ o-series) don't accept ``"none"`` as a reasoning_effort value, so we only
+ use it for these specific GPT-5 variants.
+ """
+ if not model:
+ return False
+ m = model.lower()
+ if "gpt-5" not in m:
+ return False
+ return "codex" in m or "-pro" in m or "/pro" in m
+
+
+def reasoning_effort_for(agent_id: str | None, model: str | None) -> ReasoningEffort:
+ """Resolve the reasoning_effort to actually send to LiteLLM.
+
+ - Reads the configured tier via :func:`get_reasoning_effort`.
+ - For configured ``"minimal"``:
+ * keep ``"minimal"`` on GPT-5 base / mini / nano / 5.x;
+ * map to ``"none"`` on GPT-5 codex / pro (which support ``"none"``
+ but not ``"minimal"``);
+ * fall back to ``"low"`` on every other reasoning model.
+ - For configured ``"none"`` on a non-supporting model, fall back to
+ ``"low"``.
+ """
+ effort = get_reasoning_effort(agent_id)
+ if effort == "minimal":
+ if _supports_minimal(model):
+ return "minimal"
+ if _supports_none(model):
+ return "none"
+ return "low"
+ if effort == "none" and not _supports_none(model):
+ return "low"
+ return effort
diff --git a/py-src/data_formulator/agents/agent_chart_insight.py b/py-src/data_formulator/agents/agent_chart_insight.py
index 72fd9233..a3ae8aba 100644
--- a/py-src/data_formulator/agents/agent_chart_insight.py
+++ b/py-src/data_formulator/agents/agent_chart_insight.py
@@ -1,12 +1,16 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
+from data_formulator.agent_config import reasoning_effort_for
from data_formulator.agents.agent_utils import generate_data_summary, extract_json_objects
+from data_formulator.agents.agent_language import inject_language_instruction
import logging
logger = logging.getLogger(__name__)
+_AGENT_ID = "chart_insight"
+
SYSTEM_PROMPT = r'''You are a data analyst helping users understand their visualizations.
You are given a chart image along with metadata about the chart type, data fields used, and a summary of the underlying data (including schema, value ranges, and sample rows).
@@ -92,8 +96,7 @@ def run(self, chart_image_base64, chart_type, field_names, input_tables=None, n=
if self._knowledge_store:
system_prompt += self._knowledge_store.format_rules_block()
- if self.language_instruction:
- system_prompt = system_prompt + "\n\n" + self.language_instruction
+ system_prompt = inject_language_instruction(system_prompt, self.language_instruction)
messages = [
{"role": "system", "content": system_prompt},
@@ -103,7 +106,7 @@ def run(self, chart_image_base64, chart_type, field_names, input_tables=None, n=
logger.debug(f"ChartInsightAgent: analyzing {chart_type} chart with fields {field_names}")
logger.info(f"[ChartInsightAgent] run start | chart_type={chart_type}")
- response = self.client.get_completion(messages=messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
candidates = []
for choice in response.choices:
diff --git a/py-src/data_formulator/agents/agent_chart_restyle.py b/py-src/data_formulator/agents/agent_chart_restyle.py
index d59eb90f..61edc4d6 100644
--- a/py-src/data_formulator/agents/agent_chart_restyle.py
+++ b/py-src/data_formulator/agents/agent_chart_restyle.py
@@ -23,7 +23,13 @@
import logging
from typing import Any
+from data_formulator.agent_config import reasoning_effort_for
+logger = logging.getLogger(__name__)
+
+_AGENT_ID = "chart_restyle"
+
from data_formulator.agents.agent_utils import extract_json_objects
+from data_formulator.agents.agent_language import inject_language_instruction
logger = logging.getLogger(__name__)
@@ -130,9 +136,7 @@ def run(
user_text = "\n".join(parts)
- system_prompt = SYSTEM_PROMPT
- if self.language_instruction:
- system_prompt = system_prompt + "\n\n" + self.language_instruction
+ system_prompt = inject_language_instruction(SYSTEM_PROMPT, self.language_instruction)
messages = [
{"role": "system", "content": system_prompt},
@@ -141,7 +145,7 @@ def run(
logger.info("[ChartRestyleAgent] run start | chart_type=%s", chart_type)
- response = self.client.get_completion(messages=messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
for choice in response.choices:
content = choice.message.content or ""
diff --git a/py-src/data_formulator/agents/agent_code_explanation.py b/py-src/data_formulator/agents/agent_code_explanation.py
index 8819de42..43d78535 100644
--- a/py-src/data_formulator/agents/agent_code_explanation.py
+++ b/py-src/data_formulator/agents/agent_code_explanation.py
@@ -2,39 +2,41 @@
# Licensed under the MIT License.
import json
+from data_formulator.agent_config import reasoning_effort_for
from data_formulator.agents.agent_utils import generate_data_summary, extract_json_objects, extract_code_from_gpt_response
+from data_formulator.agents.agent_language import inject_language_instruction
import logging
logger = logging.getLogger(__name__)
+_AGENT_ID = "code_explanation"
-SYSTEM_PROMPT = r'''You are a data scientist to help user explain derived data concepts,
-so that a non-coder can clearly understand what new fields mean. You are provided with a summary of the input data, and the transformation code.
-
-Your goal:
-1. Generate a list of explanations for new fields (fields not from the input data) that introduce metrics/concepts that are not obvious from the code.
- - provide a declarative definition that explains the new field, use a mathematical notation if applicable.
- - only include new fields explanation of new metrics that are involved in computation (e.g., ROI, commerical_success_score)
- - *DO NOT* explain trivial new fields like "Decade" or "Avg_Rating", "US_Sales" that are self-explanatory.
- - Avoid explaining fields that are simple aggregate of fields in the original data (min_score, avg_value, count, etc.)
- - When a field involves mathematical computation, you can use LaTeX math notation in the explanation. Format mathematical expressions using:
- - Inline math: `\( ... \)` for formulas within text
- - Block math: `\[ ... \]` for standalone formulas
- - Examples: `\( \frac{\text{Revenue}}{\text{Cost}} \)` for ratios, `\[ \text{Score} = \text{Rating} \times \text{Worldwide\_Gross} \]` for formulas
- - note: when using underscores as part of the text, you need to escape them with a backslash, e.g., `\_`
- - Note: don't use math notation for fields whose computation is trivial (use plain english), it will likely be confusing to the reader.
- Only use math notation for fields that can not be easilyexplained in plain english. Use it sparingly.
-2. If there are multiple fields that have the similar computation, you can explain them together in one explanation.
- - in "field", you can provide a list of fields in format of "field1, field2, ..."
- - in "explanation", you can provide a single explanation for the computation of the fields.
- - for example, if you have fields like "Norm_Rating", "Norm_Gross", "Critical_Commercial_Score", you can explain Norm_Rating, Norm_Gross together in one explanation and explain Critical_Commercial_Score in another explanation.
-3. If the code is about statistical analysis, you should explain the statistical analysis in the explanation as a concept named "Statistical Analysis".
- - explain how you model the data, which fields are used, how data processing is done, and what models are used.
- - suggest some other modeling approaches that can be used to analyze the data in the explanation as well.
-
-The focus is to explain how new fields are computed, don't generate explanation for low-level actions like "return", "load data" etc.
-If there are no non-trivial new fields/concepts, return an empty list.
+
+SYSTEM_PROMPT = r'''You help a non-coder understand how newly derived fields are computed.
+
+For each non-trivial derived field, output:
+ 1. the field name(s)
+ 2. a short formula — use actual field names (e.g. `Profit = Revenue - Cost`),
+ and reach for formal math (\sum, \frac, etc.) only when it's the clearest
+ way to express the computation.
+
+A brief one-line description before the formula is allowed when it adds clarity
+(e.g. "Within each Major\_category:"). Otherwise keep it to just the formula.
+
+Skip fields whose computation is trivial or obvious from the name
+(count/min/max/avg/sum, year/decade extraction, simple rename, etc.).
+Group fields that share the same formula shape into one entry
+(`"field": "f1, f2, ..."`).
+
+For statistical-analysis code (regression, clustering, hypothesis tests),
+emit a single entry with `"field": "Statistical Analysis"` containing the
+model's defining equation(s).
+
+LaTeX: inline `\( ... \)`, block `\[ ... \]`, escape underscores as `\_`.
+Prefer inline for short formulas, block when there's vertical structure.
+
+If nothing is worth showing, return an empty list.
Provide the result as a JSON block (start with ```json) in the [CONCEPTS EXPLANATION] section.
@@ -127,15 +129,15 @@ def extract_decade(date_str):
```json
[
- {
- "field": "Norm_Rating, Norm_Gross",
- "explanation": "Normalized values that scale the original values between 0 and 1 using min-max normalization. Formula: -BSLASH-(-BSLASH-text{Normalized} = -BSLASH-frac{-BSLASH-text{Value} - -BSLASH-text{Min}}{-BSLASH-text{Max} - -BSLASH-text{Min}} -BSLASH-)"
- },
- {
- "field": "Critical_Commercial_Score",
- "explanation": "The critical-commercial success score combines **Norm_Rating** and **Norm_Gross** to represent a movie's critical acclaim and commercial performance. Formula: -BSLASH-(-BSLASH-text{Critical-BSLASH-_Commercial-BSLASH-_Score} = -BSLASH-text{Norm-BSLASH-_Rating} -BSLASH-times -BSLASH-text{Norm-BSLASH-_Gross} -BSLASH-)"
+ {
+ "field": "Norm_Rating, Norm_Gross",
+ "explanation": "-BSLASH-[ -BSLASH-text{Normalized} = -BSLASH-frac{x - -BSLASH-min(x)}{-BSLASH-max(x) - -BSLASH-min(x)} -BSLASH-]"
+ },
+ {
+ "field": "Critical_Commercial_Score",
+ "explanation": "-BSLASH-[ -BSLASH-text{Critical-BSLASH-_Commercial-BSLASH-_Score} = -BSLASH-text{Norm-BSLASH-_Rating} -BSLASH-times -BSLASH-text{Norm-BSLASH-_Gross} -BSLASH-]"
}
-]
+]
'''
class CodeExplanationAgent(object):
@@ -158,14 +160,12 @@ def run(self, input_tables, code, n=1):
logger.debug(user_query)
logger.info(f"[CodeExplanationAgent] run start")
- system_prompt = SYSTEM_PROMPT
- if self.language_instruction:
- system_prompt = system_prompt + "\n\n" + self.language_instruction
+ system_prompt = inject_language_instruction(SYSTEM_PROMPT, self.language_instruction)
messages = [{"role":"system", "content": system_prompt},
{"role":"user","content": user_query}]
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages = messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
candidates = []
for choice in response.choices:
diff --git a/py-src/data_formulator/agents/agent_data_clean_stream.py b/py-src/data_formulator/agents/agent_data_clean_stream.py
deleted file mode 100644
index 3fcfe745..00000000
--- a/py-src/data_formulator/agents/agent_data_clean_stream.py
+++ /dev/null
@@ -1,240 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from data_formulator.agents.agent_utils import extract_json_objects
-from data_formulator.agents.web_utils import download_html_content
-
-import logging
-import re
-import json
-import traceback
-
-logger = logging.getLogger(__name__)
-
-
-def parse_table_sections(text):
- """Parse [TABLE_START] to [TABLE_END] sections and extract metadata and content."""
- tables = []
-
- # Split by [TABLE_START] and process each section
- sections = text.strip().split('[TABLE_START]')
-
- print(sections)
-
- for i, section in enumerate(sections[1:], 1): # Skip first empty section
-
- # Find the end of this table section
- if '[TABLE_END]' not in section:
- continue
-
- table_section = section.split('[TABLE_END]')[0]
-
- metadata_index = table_section.find('[METADATA]')
- content_index = table_section.find('[CONTENT]')
-
- # Extract metadata between [METADATA] and ```
- if metadata_index != -1 and content_index != -1:
- metadata_block = table_section[metadata_index + len('[METADATA]'):content_index]
- metadata_json = extract_json_objects(metadata_block)[0]
-
- # Extract content between [CONTENT] and end
- if content_index != -1:
- content_block = table_section[content_index + len('[CONTENT]'):].strip()
-
- # Create table object
- table = {
- "name": metadata_json.get('name', 'unknown'),
- "context": metadata_json.get('context', ''),
- "content": {
- "type": metadata_json.get('type', 'csv'),
- "value": content_block
- }
- }
-
- tables.append(table)
-
- return tables
-
-
-SYSTEM_PROMPT = '''You are a data scientist to help user to generate, extract data from image, or clean a text input into a structured csv table.
-
-If there are multiple tables in the raw data, you should extract them all.
-Each table can either be a csv block or a url (url of an image that you think contains data).
-- csv block: a string of csv content (if the content is already available from the input)
-- image url: link to an image that contains data
-
-Based on the raw data provided by the user, extract tables:
-- each extracted table should be wrapped in a section, its metadata is a json object describes its name and type in [METADATA] section.
-- if the table is a csv block, it should be wrapped in [CONTENT] tags. Do not wrap it in any other tags, just write plain csv content in the [CONTENT].
-- if the table is an image url, [CONTENT] should be the url.
-- when there are multiple tables, generate one table at a time.
-
-Output only extract tables, no other text should be included. Format:
-
-[TABLE_START]
-
-[METADATA]
-
-```json
-{
- "name": "...", // suggest a descriptive, meaningful but short name for this dataset, no more than 5 words, if there are duplicate names, add a suffix -1, -2, etc. (e.g., "sales-2024", "us-customer-survey-2024", "seattle-weather-forecast")
- "type": "csv" | "image_url",
- "context": "..." // a paragraph summarizing the original source document or image this table was extracted from. Include: what the document is about, its main topic, any relevant background, and what the table represents within that context. This summary will be used by downstream agents to understand the data, so be descriptive and informative. (around 50-100 words)
-}
-```
-
-[CONTENT]
-
-... // the csv block or image url, directly output the content, no other text should be included and don't wrap it in any other tags.
-
-[TABLE_END]
-
-**Important:**
-- NEVER make assumptions or judgments about a person's gender, biological sex, sexuality, religion, race, nationality, ethnicity, political stance, socioeconomic status, mental health, invisible disabilities, medical conditions, personality type, social impressions, emotional state, and cognitive state.
-- NEVER create formulas that could be used to discriminate based on age. Ageism of any form (explicit and implicit) is strictly prohibited.
-
-**Multiple tables:**
-- if the raw data contains multiple tables, based on the user's instruction to decide which table to extract.
-- if the user doesn't specify which tables to extract, extract all tables.
-- if there are multiple tables yet they can be too large, only extract up to 200 rows for each table.
-
-**Instructions for creating csv blocks:**
-* the output should be a structured csv table:
- - if the raw data is unstructured, structure it into a csv table. If the table is in other formats, transform it into a csv table.
- - if the raw data contain other informations other than the table (e.g., title, subtitle, footer, summary, etc.), remove surrounding texts that does not belong to the table, so that the table conforms to csv format.
- - if the raw data contains multiple levels of header, make it a flat table. It's ok to combine multiple levels of headers to form the new header to not lose information.
- - the csv table should have the same number of cells for each line, according to the header. If there are some rows with missing values, patch them with empty values.
- - if the header row misses some columns, add their corresponding column names. E.g., when the header doesn't have an index column, but every row has an index value, add the missing column header.
-* clean up messy column names:
- - if the column name contains special characters like "*", "?", "#", "." remove them.
-* csv value format:
- - if a column is number but some cells has annotations like "*" "?" or brackets, clean them up.
- - if values of a column is all numbers but has units like ($, %, s), remove the unit in the value cells, convert them to number, note unit in the header of this column.
- - you don't need to convert format of the cell.
-
-**Instructions for creating image url:**
-- based on the context provided in the prompt and raw input material, decide which url in the raw data may cotain the data we would like to extract (like an image contains structured data).
-
-**Instructions for generating synthetic data:**
-- NEVER generate data that has implicit bias as noted above, if that happens, neutralize the data.
-- If the user doesn't indicate how many rows to be generated, plan in generating a dataset with 20-30 rows depending on the content.
-
-**IMPORTANT:**
-- when the user provide an image and ask to extract data, you should extract data from the image into a csv block.
-- get all tables that contain structured data from the raw data, including the csv blocks and image urls.
-'''
-
-
-EXAMPLE = '''
-Rank NOC Gold Silver Bronze Total
-1 South Korea 5 1 1 7
-2 France* 0 1 1 2
- United States 0 1 1 2
-4 China 0 1 0 1
- Germany 0 1 0 1
-6 Mexico 0 0 1 1
- Turkey 0 0 1 1
-Totals (7 entries) 5 5 5 15
-'''
-
-class DataCleanAgentStream(object):
-
- def __init__(self, client, language_instruction=""):
- self.client = client
- self.language_instruction = language_instruction
-
- def stream(self, prompt, artifacts=[], dialog=[]):
- """derive a new concept based on the raw input data
- Args:
- prompt (str): the prompt to the agent
- artifacts (list): the artifacts to the agent of format
- [{"type": "image_url", "content": ...}, {"type": "web_url", "content": ...}, ...]
- dialog (list): the dialog history
- Returns:
- generator: the result of the agent
- """
-
- content = []
-
- for artifact in artifacts:
- if artifact['type'] == 'image_url':
- content.append({
- 'type': 'image_url',
- 'image_url': {
- "url": artifact['content'],
- "detail": "high"
- }
- })
- elif artifact['type'] == 'web_url':
- try:
- content.append({
- 'type': 'text',
- 'text': f"[HTML CONTENT]\n\n{download_html_content(artifact['content'])}"
- })
- except Exception as e:
- raise Exception('unable to download html from url ' + artifact['content'])
-
- content.append({
- 'type': 'text',
- 'text': f'''{prompt}'''
- })
-
- user_prompt = {
- 'role': 'user',
- 'content': content
- }
-
- logger.debug(user_prompt)
- logger.info(f"[DataCleanAgent] run start (streaming)")
-
- prompt_text = SYSTEM_PROMPT
- if self.language_instruction:
- prompt_text = prompt_text + "\n\n" + self.language_instruction
-
- system_message = {
- 'role': 'system',
- 'content': [ {'type': 'text', 'text': prompt_text}]
- }
-
- messages = [
- system_message,
- *[message for message in dialog if message['role'] != 'system'],
- user_prompt
- ]
-
- ###### the part that calls open_ai
- stream = self.client.get_completion(messages = messages, stream=True)
-
- accumulated_content = ""
-
- for part in stream:
- if hasattr(part, 'choices') and len(part.choices) > 0:
- delta = part.choices[0].delta
- if hasattr(delta, 'content') and delta.content:
- accumulated_content += delta.content
-
- # Stream each character for real-time display as JSON
- yield delta.content
-
- # Parse the final content the same way as the non-streaming version
- logger.debug("\n=== Python Data Clean Agent Stream ===>\n")
- logger.debug(accumulated_content + "\n")
-
- # Parse table sections from the accumulated content
- tables = parse_table_sections(accumulated_content)
-
- if len(tables) > 0:
- # Use the same format as non-streaming version - return the parsed data directly
- result = {
- 'status': 'ok',
- 'content': tables,
- }
- else:
- result = {'status': 'other error', 'content': 'unable to extract tables from response', 'content_code': 'agent.unableExtractTables'}
-
- result['dialog'] = [*messages, {"role": "assistant", "content": accumulated_content}]
- result['agent'] = 'DataCleanAgentStream'
- logger.info(f"[DataCleanAgent] run done | status={result.get('status', '?')}")
-
- # add a newline to the beginning of the result to separate it from the previous result
- yield '\n' + json.dumps(result, ensure_ascii=False) + '\n'
\ No newline at end of file
diff --git a/py-src/data_formulator/agents/agent_data_load.py b/py-src/data_formulator/agents/agent_data_load.py
index 1be2b397..baffd103 100644
--- a/py-src/data_formulator/agents/agent_data_load.py
+++ b/py-src/data_formulator/agents/agent_data_load.py
@@ -3,8 +3,10 @@
import json
+from data_formulator.agent_config import reasoning_effort_for
from data_formulator.agents.agent_utils import extract_json_objects, generate_data_summary
from data_formulator.agents.agent_diagnostics import AgentDiagnostics
+from data_formulator.agents.agent_language import inject_language_instruction
from data_formulator.agents.semantic_types import (
generate_semantic_types_prompt,
)
@@ -13,6 +15,8 @@
logger = logging.getLogger(__name__)
+_AGENT_ID = "data_load"
+
SYSTEM_PROMPT = '''You are a data scientist to help user infer data types based off the table provided by the user.
Given a dataset provided by the user,
@@ -166,9 +170,7 @@ def __init__(self, client, workspace, language_instruction="", model_info=None):
self.workspace = workspace
self.language_instruction = language_instruction
- self.system_prompt = SYSTEM_PROMPT
- if language_instruction:
- self.system_prompt = self.system_prompt + "\n\n" + language_instruction
+ self.system_prompt = inject_language_instruction(SYSTEM_PROMPT, language_instruction)
self._diag = AgentDiagnostics(
agent_name="DataLoadAgent",
@@ -199,7 +201,7 @@ def run(self, input_data, n=1):
messages = [{"role":"system", "content": self.system_prompt},
{"role":"user","content": user_query}]
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages = messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
candidates = []
for choice in response.choices:
diff --git a/py-src/data_formulator/agents/agent_data_loading_chat.py b/py-src/data_formulator/agents/agent_data_loading_chat.py
index 4182edbe..61d3a0e6 100644
--- a/py-src/data_formulator/agents/agent_data_loading_chat.py
+++ b/py-src/data_formulator/agents/agent_data_loading_chat.py
@@ -3,8 +3,7 @@
"""Conversational data loading agent.
-Replaces the old DataCleanAgentStream with a general-purpose
-conversational agent that can:
+General-purpose conversational agent that can:
- Extract tables from images / text / files
- Execute Python code in a sandboxed environment
- Show inline table previews
@@ -17,14 +16,16 @@
import os
import re
-import litellm
-import openai
import pandas as pd
-from data_formulator.agents.agent_data_clean_stream import parse_table_sections
+from data_formulator.agent_config import reasoning_effort_for
+from data_formulator.agents.agent_utils import accumulate_reasoning_content
+from data_formulator.datalake.parquet_utils import df_to_safe_records
logger = logging.getLogger(__name__)
+_AGENT_ID = "data_loading_chat"
+
# ---------------------------------------------------------------------------
# System prompt
@@ -34,49 +35,71 @@
You are a data assistant helping users load and prepare data for analysis in Data Formulator.
Tools available:
-- read_file / write_file / list_directory — workspace filesystem
+- read_file / write_file / list_directory — workspace filesystem (scratch/ uploads)
- execute_python — run Python (pandas, numpy, DuckDB). All DataFrames are auto-saved to scratch/.
-- list_sample_datasets — list available built-in datasets with their tables and exact call syntax
-- show_user_data_preview — show interactive table preview with Load button
-- search_data_candidates — search across all data sources for tables matching a keyword
-- read_candidate_metadata — read detailed metadata for a table from a connected source
+- list_data — browse the catalog hierarchy of connected sources (cache-only, fast)
+- find_data — regex search across cached catalogs (names, descriptions, columns)
+- describe_data — read full metadata for one table
+- show_user_data_preview — show interactive table preview with Load button (for execute_python results or extracted tables only)
- propose_load_plan — propose a multi-table loading plan for user confirmation
CRITICAL: You MUST call the show_user_data_preview tool to show data. Do NOT just describe data in text.
-Four workflows:
-
-**Workflow 1 — Sample dataset:**
-1. Call list_sample_datasets to see what's available (returns exact dataset_name to use)
-2. Call show_user_data_preview(dataset_name="") — ALL tables in the dataset are shown
+Three workflows:
-**Workflow 2 — Uploaded file or code processing:**
+**Workflow 1 — Uploaded file or code processing:**
1. Inspect files with read_file/list_directory
2. Process with execute_python (DataFrames auto-saved to scratch/)
3. Call show_user_data_preview(saved_dfs=["df_name"])
-**Workflow 3 — Unstructured text or image extraction:**
+**Workflow 2 — Unstructured text or image extraction:**
1. Extract table into CSV format
2. Call show_user_data_preview(tables=[{{"name": "...", "data": "col1,col2\\n..."}}])
-**Workflow 4 — Find and load data from connected sources:**
-1. Call search_data_candidates(query="...", scope="all") to find relevant tables
-2. For EACH promising not-imported table, call read_candidate_metadata(source_id, table_key) to inspect columns and understand available values
-3. Based on the column metadata, decide which columns to filter on and what values to use
-4. Call propose_load_plan(candidates=[...], reasoning="...") — the UI shows a confirmation card
-5. Keep your text brief after propose_load_plan. The UI handles the rest.
+**Workflow 3 — Find and load data from connected sources (including sample datasets):**
+1. Call find_data(query="...") to search. The query is a case-insensitive regex —
+ use alternation for synonyms ("orders|sales|revenue"), anchors ("^fact_"), word
+ boundaries ("\\border\\b"), or optional groups ("customers?") when helpful. Escape
+ "." if you mean a literal dot. Pass exclude="_staging|_test" to drop noise.
+ When search is ambiguous, restrict with scope="" or
+ scope=":".
+2. If find_data returns nothing useful or is ambiguous, fall back to list_data:
+ - list_data() → which sources exist
+ - list_data(source_id="...") → top-level folders / tables
+ - list_data(source_id, path=[...]) → drill in
+ - Pass filter="..." (plain substring, not regex) when a directory has many entries.
+ Responses are capped at 200 entries; if truncated:true, narrow with filter or
+ switch back to find_data with a scope.
+3. For EACH promising not-imported table, call describe_data(source_id, table_key)
+ to inspect columns and understand available values.
+4. Based on column metadata, decide which columns to filter on and what values to use.
+5. Call propose_load_plan(candidates=[...], reasoning="...") — the UI shows a
+ confirmation card.
+6. Keep your text brief after propose_load_plan. The UI handles the rest.
+
+Workflow selection rubric (apply in order):
+- User pasted/uploaded data, attached an image, or asked to process scratch files → Workflow 1 or 2.
+- User asked "what data do you have / what's available / which sources are connected" → call
+ list_data() — it returns the per-source summary. Drill in with list_data(source_id, ...).
+ Do NOT rely solely on the summary below; it only shows counts.
+- Otherwise, if connected data sources are listed below AND the user is describing data they want
+ to analyze (an entity, metric, time range, region, product, demo data, etc.) → start with
+ Workflow 3. Try regex variants (English + the user's language, synonyms, table-name fragments,
+ folder names) with find_data before giving up. The built-in 'sample_datasets' source is
+ included automatically.
+- Only fall back to synthetic data after Workflow 3 returned no plausible matches.
Rules:
- After show_user_data_preview or propose_load_plan, keep text VERY brief. The UI shows the preview automatically.
-- For sample datasets, NEVER use execute_python or write_file to recreate them.
+- show_user_data_preview is ONLY for: (a) DataFrames you actually produced with execute_python via saved_dfs=, or (b) tables you literally extracted from a user-provided image or pasted text via tables=. NEVER use show_user_data_preview(tables=...) to narrate, describe, or invent contents of a connector-sourced table. To load ANY table from a connected source (including sample_datasets), you MUST use propose_load_plan.
+- For sample datasets, NEVER use execute_python or write_file to recreate them — use Workflow 3.
- execute_python auto-saves ALL DataFrames created in code.
-- Use Workflow 4 when the user describes an analysis goal and you need to find relevant data from connected sources.
-- In propose_load_plan, always pass source_id and table_key exactly from search_data_candidates/read_candidate_metadata.
+- In propose_load_plan, always pass source_id and table_key exactly from find_data/describe_data. If propose_load_plan returns an error listing valid source_ids, re-run find_data with a better query and retry — do NOT guess IDs.
- Do NOT set row_limit in propose_load_plan; the system applies the user's configured global limit automatically.
Filter rules for propose_load_plan:
-- You MUST call read_candidate_metadata BEFORE proposing filters. Do NOT guess column names or values.
-- Use the column names exactly as returned by read_candidate_metadata. Do NOT invent column names.
+- You MUST call describe_data BEFORE proposing filters. Do NOT guess column names or values.
+- Use the column names exactly as returned by describe_data. Do NOT invent column names.
- Filter values must be plain values without SQL wildcards. WRONG: "%奔图%". CORRECT: "奔图".
- For partial text matching, use operator ILIKE — the backend adds wildcards automatically.
- For exact matching of a known category value, use operator EQ.
@@ -86,8 +109,8 @@
Current date and time: {current_time}
Currently loaded workspace tables: {table_names}
-Connected data sources: {connector_summary}
-Sample datasets are available — call list_sample_datasets to see them.
+Connected data sources:
+{connector_summary}
IMPORTANT:
- When extracting tables: clean column names, remove units from values (note in headers), flatten multi-level headers.
@@ -183,11 +206,26 @@
{
"type": "function",
"function": {
- "name": "list_sample_datasets",
- "description": "List available built-in sample datasets with their tables and the exact dataset_name to use with show_user_data_preview.",
+ "name": "list_data",
+ "description": (
+ "Browse the catalog of connected data sources. Cache-only, fast.\n"
+ "- No args: per-source summary (source_id, table_count, is_hierarchical).\n"
+ "- source_id only: top-level entries (folders with table counts, plus root tables).\n"
+ "- source_id + path: direct children at that hierarchy level.\n"
+ "- filter: case-insensitive substring on the next path segment / table name (no regex here).\n"
+ "Workspace tables are already in the system prompt and are not repeated."
+ ),
"parameters": {
"type": "object",
- "properties": {},
+ "properties": {
+ "source_id": {"type": "string", "description": "Data source identifier. Omit for source-level summary."},
+ "path": {
+ "type": "array",
+ "items": {"type": "string"},
+ "description": "Hierarchy path as an array of segments (e.g. ['sales', 'fy26']).",
+ },
+ "filter": {"type": "string", "description": "Substring filter on the next path segment / table name."},
+ },
"required": [],
},
},
@@ -197,18 +235,14 @@
"function": {
"name": "show_user_data_preview",
"description": (
- "Show interactive table preview(s) with Load button. Three modes (use exactly one):\n"
- "1. dataset_name: load built-in sample dataset by name\n"
- "2. saved_dfs: reference DataFrames auto-saved by execute_python (by variable name)\n"
- "3. tables: inline CSV data for direct extraction from text/images\n"
+ "Show interactive table preview(s) with Load button. Two modes (use exactly one):\n"
+ "1. saved_dfs: reference DataFrames auto-saved by execute_python (by variable name)\n"
+ "2. tables: inline CSV data for direct extraction from text/images\n"
+ "For tables in a connected source (including sample_datasets), use propose_load_plan instead."
),
"parameters": {
"type": "object",
"properties": {
- "dataset_name": {
- "type": "string",
- "description": "Exact dataset name from list_sample_datasets (e.g. 'Space launches'). All tables in the dataset are shown.",
- },
"saved_dfs": {
"type": "array",
"description": "DataFrame variable names from execute_python (e.g. ['df_clean', 'df_summary'])",
@@ -234,13 +268,30 @@
{
"type": "function",
"function": {
- "name": "search_data_candidates",
- "description": "Search across all data sources (workspace tables, connected databases, sample datasets) for tables matching a keyword.",
+ "name": "find_data",
+ "description": (
+ "Regex search across cached catalogs for tables matching a query. "
+ "Searches table names, table descriptions, column names, and column descriptions.\n"
+ "- query: case-insensitive regex. Plain keywords work as literals; use alternation "
+ "(orders|sales|revenue), anchors (^fact_), word boundaries (\\border\\b), and optional "
+ "groups (customers?) when useful. Escape . if you mean a literal dot.\n"
+ "- scope: 'all' (default), 'workspace', 'connected', '', or ':' "
+ "to restrict to a subtree (path is /-joined segments).\n"
+ "- exclude: optional regex on table name to drop hits (e.g. '_staging|_test').\n"
+ "- fields: subset of ['name','description','columns'] to restrict matching; default is all."
+ ),
"parameters": {
"type": "object",
"properties": {
- "query": {"type": "string", "description": "Search keyword (e.g. 'orders', 'sales')"},
- "scope": {"type": "string", "enum": ["all", "workspace", "connected"], "description": "Search scope. Default: all"},
+ "query": {"type": "string", "description": "Case-insensitive regex."},
+ "scope": {"type": "string", "description": "Search scope. Default: all"},
+ "exclude": {"type": "string", "description": "Optional regex; drops hits whose name matches."},
+ "fields": {
+ "type": "array",
+ "items": {"type": "string", "enum": ["name", "description", "columns"]},
+ "description": "Restrict matching to these fields. Default: all.",
+ },
+ "limit": {"type": "integer", "description": "Max results. Default 50, max 200."},
},
"required": ["query"],
},
@@ -249,8 +300,8 @@
{
"type": "function",
"function": {
- "name": "read_candidate_metadata",
- "description": "Read detailed metadata (columns, types, description, row count) for a specific table from a connected data source. Use source_id and table_key from search_data_candidates results.",
+ "name": "describe_data",
+ "description": "Read full metadata (columns, types, description, row count) for one table. Use source_id + table_key from find_data results.",
"parameters": {
"type": "object",
"properties": {
@@ -314,6 +365,84 @@ def _secure_filename(name: str) -> str:
return name or "unnamed"
+
+def _summarize_catalog_shape(tables: list[dict]) -> tuple[int, int]:
+ """Return ``(table_count, distinct_folder_count)`` for a catalog.
+
+ Folder count is 0 when no table has a hierarchical ``path`` (depth >= 2);
+ flat catalogs report 0 folders so the summary stays terse.
+ """
+ folders: set[str] = set()
+ any_hierarchy = False
+ for t in tables:
+ path = t.get("path") or []
+ if isinstance(path, list) and len(path) >= 2:
+ any_hierarchy = True
+ folders.add(str(path[0]))
+ return len(tables), (len(folders) if any_hierarchy else 0)
+
+
+def _build_connector_summary_block(
+ user_home,
+ *,
+ max_total_chars: int = 1200,
+) -> str:
+ """Render a compact directory of cached connector catalogs.
+
+ Only shows source IDs with table counts (and folder counts when the
+ catalog is hierarchical). The agent is expected to call ``list_data``
+ for full inventory.
+ Strictly hard-capped at ``max_total_chars``.
+ """
+ if not user_home:
+ return " none"
+ try:
+ from pathlib import Path
+
+ from data_formulator.datalake.catalog_cache import list_cached_sources, load_catalog
+ except Exception:
+ logger.debug("connector summary: imports failed", exc_info=True)
+ return " none"
+
+ try:
+ source_ids = list_cached_sources(user_home)
+ except Exception:
+ logger.debug("connector summary: list_cached_sources failed", exc_info=True)
+ return " none"
+
+ if not source_ids:
+ return " none"
+
+ user_home_path = Path(user_home)
+ lines: list[str] = []
+ for sid in sorted(source_ids):
+ try:
+ tables = load_catalog(user_home_path, sid) or []
+ except Exception:
+ logger.debug("connector summary: load_catalog failed for %s", sid, exc_info=True)
+ tables = []
+ n, k = _summarize_catalog_shape(tables)
+ if n == 0:
+ lines.append(f"- {sid}: 0 tables cached")
+ elif k > 0:
+ lines.append(
+ f"- {sid}: {n} table{'s' if n != 1 else ''} "
+ f"across {k} folder{'s' if k != 1 else ''}"
+ )
+ else:
+ lines.append(f"- {sid}: {n} table{'s' if n != 1 else ''}")
+
+ lines.append(
+ " (call list_data() for sources, list_data(source_id, ...) to drill, "
+ "or find_data(query=...) to search)"
+ )
+
+ output = "\n".join(lines)
+ if len(output) > max_total_chars:
+ output = output[:max_total_chars].rstrip() + "\n ... (truncated)"
+ return output
+
+
class DataLoadingAgent:
"""Conversational agent for data loading and extraction."""
@@ -383,6 +512,7 @@ def _agentic_loop(self, llm_messages, collected_text, actions, max_iterations):
# Accumulate streaming response
tool_calls_acc = {} # id -> {name, arguments_str}
current_text = []
+ accumulated_reasoning = None
finish_reason = None
for chunk in response:
@@ -392,6 +522,11 @@ def _agentic_loop(self, llm_messages, collected_text, actions, max_iterations):
delta = chunk.choices[0].delta
finish_reason = chunk.choices[0].finish_reason
+ # Accumulate reasoning_content (DeepSeek V4 reasoning models)
+ accumulated_reasoning = accumulate_reasoning_content(
+ accumulated_reasoning, delta
+ )
+
# Stream text tokens
if hasattr(delta, 'content') and delta.content:
collected_text.append(delta.content)
@@ -421,6 +556,8 @@ def _agentic_loop(self, llm_messages, collected_text, actions, max_iterations):
# Build assistant message with tool calls for LLM context
assistant_msg = {"role": "assistant", "content": "".join(current_text) or None}
+ if accumulated_reasoning is not None:
+ assistant_msg["reasoning_content"] = accumulated_reasoning
assistant_msg["tool_calls"] = []
for idx in sorted(tool_calls_acc.keys()):
tc = tool_calls_acc[idx]
@@ -495,30 +632,10 @@ def _agentic_loop(self, llm_messages, collected_text, actions, max_iterations):
# ------------------------------------------------------------------
def _call_llm(self, messages, stream=True):
- """Call the LLM with tool definitions, working around Client.get_completion
- not supporting a `tools` parameter."""
- if self.client.endpoint == "openai":
- client = openai.OpenAI(
- base_url=self.client.params.get("api_base", None),
- api_key=self.client.params.get("api_key", ""),
- timeout=120,
- )
- return client.chat.completions.create(
- model=self.client.model,
- messages=messages,
- tools=TOOLS,
- stream=stream,
- )
- else:
- params = self.client.params.copy()
- return litellm.completion(
- model=self.client.model,
- messages=messages,
- tools=TOOLS,
- drop_params=True,
- stream=stream,
- **params,
- )
+ """Call the LLM with tool definitions."""
+ return self.client.get_completion_with_tools(
+ messages, tools=TOOLS, stream=stream, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model),
+ )
# ------------------------------------------------------------------
# Tool execution
@@ -537,14 +654,14 @@ def _execute_tool(self, name, args):
return self._tool_list_directory(args, workspace_jail)
elif name == "execute_python":
return self._tool_execute_python(args)
- elif name == "list_sample_datasets":
- return self._tool_list_sample_datasets()
elif name == "show_user_data_preview":
return self._tool_show_user_data_preview(args, scratch_jail)
- elif name == "search_data_candidates":
- return self._tool_search_data_candidates(args)
- elif name == "read_candidate_metadata":
- return self._tool_read_candidate_metadata(args)
+ elif name == "list_data":
+ return self._tool_list_data(args)
+ elif name == "find_data":
+ return self._tool_find_data(args)
+ elif name == "describe_data":
+ return self._tool_describe_data(args)
elif name == "propose_load_plan":
return self._tool_propose_load_plan(args)
else:
@@ -674,7 +791,7 @@ def _tool_execute_python(self, args):
"path": f"scratch/{safe_name}.csv",
"rows": len(df),
"columns": list(df.columns),
- "preview": df.head(3).to_dict(orient="records"),
+ "preview": df_to_safe_records(df.head(3)),
}
if saved:
@@ -692,19 +809,17 @@ def _tool_execute_python(self, args):
return {"stdout": "", "error": "Code execution failed"}
def _tool_show_user_data_preview(self, args, scratch_jail):
- """Unified data preview with 3 modes."""
- dataset_name = args.get("dataset_name")
+ """Unified data preview. To load from a connected source (including
+ the built-in 'sample_datasets'), use propose_load_plan instead."""
saved_dfs = args.get("saved_dfs")
tables = args.get("tables")
- if dataset_name:
- return self._preview_sample_dataset(dataset_name)
- elif saved_dfs:
+ if saved_dfs:
return self._preview_saved_dfs(saved_dfs, scratch_jail)
elif tables:
return self._preview_inline_tables(tables, scratch_jail)
else:
- return {"error": "Provide one of: dataset_name, saved_dfs, or tables."}
+ return {"error": "Provide one of: saved_dfs or tables. For connected-source tables (including sample_datasets), use propose_load_plan."}
def _preview_saved_dfs(self, df_names, scratch_jail):
"""Preview DataFrames auto-saved by execute_python."""
@@ -729,7 +844,7 @@ def _preview_saved_dfs(self, df_names, scratch_jail):
"type": "preview_table",
"name": name,
"columns": list(df.columns),
- "sample_rows": df.head(5).to_dict(orient="records"),
+ "sample_rows": df_to_safe_records(df.head(5)),
"total_rows": len(df),
"csv_scratch_path": f"scratch/{safe_name}.csv",
})
@@ -756,7 +871,7 @@ def _preview_inline_tables(self, tables, scratch_jail):
"type": "preview_table",
"name": name,
"columns": list(df.columns),
- "sample_rows": df.head(5).to_dict(orient="records"),
+ "sample_rows": df_to_safe_records(df.head(5)),
"total_rows": len(df),
"csv_scratch_path": f"scratch/{name}.csv",
})
@@ -791,7 +906,7 @@ def _preview_scratch_files(self, scratch_files, scratch_dir):
"type": "preview_table",
"name": table_name,
"columns": list(df.columns),
- "sample_rows": df.head(5).to_dict(orient="records"),
+ "sample_rows": df_to_safe_records(df.head(5)),
"total_rows": len(df),
"csv_scratch_path": file_path,
})
@@ -801,107 +916,167 @@ def _preview_scratch_files(self, scratch_files, scratch_dir):
return {"actions": actions}
- def _tool_list_sample_datasets(self):
- """Return structured list of available datasets with call syntax."""
- from data_formulator.example_datasets_config import EXAMPLE_DATASETS
+ # ------------------------------------------------------------------
+ # Data discovery tools
+ # ------------------------------------------------------------------
- datasets = []
- for ds in EXAMPLE_DATASETS:
- tables = []
- for t in ds.get("tables", []):
- url = t.get("url", "")
- table_name = url.split("/")[-1].split(".")[0] if url else "table"
- sample = t.get("sample", [])
- if isinstance(sample, list) and sample:
- cols = list(sample[0].keys()) if isinstance(sample[0], dict) else []
- elif isinstance(sample, str) and sample.strip():
- header = sample.strip().split("\n")[0]
- sep = "," if t.get("format") == "csv" else "\t"
- cols = header.split(sep)
- else:
- cols = []
- tables.append({"table_name": table_name, "columns_preview": cols[:6]})
-
- datasets.append({
- "dataset_name": ds["name"],
- "description": ds.get("description", ""),
- "tables": tables,
- "call": f'show_user_data_preview(dataset_name="{ds["name"]}")',
- })
-
- return {"datasets": datasets}
-
- def _preview_sample_dataset(self, dataset_name):
- """Build preview actions for a built-in sample dataset (exact match)."""
- from data_formulator.example_datasets_config import EXAMPLE_DATASETS
-
- matched = None
- for ds in EXAMPLE_DATASETS:
- if ds["name"].lower() == dataset_name.lower().strip():
- matched = ds
- break
+ def _tool_list_data(self, args):
+ """Browse the catalog hierarchy.
- if not matched:
- available = ", ".join(ds["name"] for ds in EXAMPLE_DATASETS)
- return {"error": f"Dataset '{dataset_name}' not found. Available: {available}. Use list_sample_datasets to see exact names."}
-
- tables_info = []
- for table in matched.get("tables", []):
- sample = table.get("sample", [])
- if isinstance(sample, list) and len(sample) > 0:
- columns = list(sample[0].keys()) if isinstance(sample[0], dict) else []
- tables_info.append({
- "table_url": table.get("url", ""),
- "format": table.get("format", "json"),
- "columns": columns,
- "sample_rows": sample[:5],
- "total_sample_rows": len(sample),
- })
- elif isinstance(sample, str) and sample.strip():
- try:
- df = pd.read_csv(io.StringIO(sample.strip()),
- sep="," if table.get("format") == "csv" else "\t")
- tables_info.append({
- "table_url": table.get("url", ""),
- "format": table.get("format", "csv"),
- "columns": list(df.columns),
- "sample_rows": df.head(5).to_dict(orient="records"),
- "total_sample_rows": len(df),
- })
- except Exception:
- tables_info.append({
- "table_url": table.get("url", ""),
- "format": table.get("format", "csv"),
- "columns": [],
- "sample_rows": [],
- "total_sample_rows": 0,
- })
+ Three modes:
+ * no args → per-source summary
+ * source_id only → top-level entries of that source
+ * source_id + path → direct children at that level
- actions = [{
- "type": "load_sample_dataset",
- "name": matched["name"],
- "description": matched.get("description", ""),
- "live": matched.get("live", False),
- "refreshIntervalSeconds": matched.get("refreshIntervalSeconds"),
- "tables": tables_info,
- }]
+ Cache-only. Workspace tables are not included; they're already in the
+ system prompt. See design-docs/32-data-loading-agent-navigation.md §3.1.
+ """
+ from data_formulator.datalake.catalog_cache import (
+ list_path_children,
+ list_sources_summary,
+ )
- return {"actions": actions}
+ user_home = getattr(self.workspace, "user_home", None)
+ if not user_home:
+ return {"sources": []}
- # ------------------------------------------------------------------
- # Data discovery tools
- # ------------------------------------------------------------------
+ source_id = (args.get("source_id") or "").strip()
+ if not source_id:
+ try:
+ return {"sources": list_sources_summary(user_home)}
+ except Exception:
+ logger.debug("list_data: list_sources_summary failed", exc_info=True)
+ return {"sources": []}
- def _tool_search_data_candidates(self, args):
- """Search across workspace + connector catalog for matching tables."""
- from data_formulator.agents.context import handle_search_data_tables
- query = args.get("query", "")
- scope = args.get("scope", "all")
- text = handle_search_data_tables(query, scope, self.workspace)
- return {"result": text}
+ path = args.get("path") or []
+ if not isinstance(path, list):
+ return {"error": "path must be an array of strings"}
+ filter_arg = args.get("filter")
+
+ try:
+ return list_path_children(
+ user_home, source_id, path=path, filter=filter_arg,
+ )
+ except Exception as exc:
+ logger.debug("list_data: list_path_children failed", exc_info=True)
+ return {"error": f"list_data failed: {exc}"}
+
+ def _tool_find_data(self, args):
+ """Regex search across cached catalogs.
+
+ ``scope`` accepts: 'all' (default), 'workspace', 'connected',
+ '', or ':'. The
+ path-scoped form restricts catalog search to a subtree.
+
+ Workspace tables are searched with a plain substring match (they're
+ small, regex-on-name has little extra value there). Catalog cache
+ search is regex-based. See design-docs §3.2.
+ """
+ from data_formulator.datalake.catalog_cache import (
+ CatalogSearchError,
+ search_catalog_cache,
+ )
+
+ query = (args.get("query") or "").strip()
+ if not query:
+ return {"error": "query is required"}
+
+ scope_raw = (args.get("scope") or "all").strip()
+ exclude = args.get("exclude") or None
+ fields = args.get("fields") or None
+ limit = args.get("limit")
+ try:
+ limit = max(1, min(int(limit), 200)) if limit else 50
+ except (TypeError, ValueError):
+ limit = 50
+
+ # ── Parse scope ───────────────────────────────────────────────
+ search_workspace = False
+ source_ids: list[str] | None = None
+ path_prefix: list[str] | None = None
+
+ if scope_raw == "all":
+ search_workspace = True
+ elif scope_raw == "workspace":
+ search_workspace = True
+ source_ids = [] # skip catalog cache entirely
+ elif scope_raw == "connected":
+ pass # catalog only, all sources
+ elif ":" in scope_raw:
+ sid, _, path_str = scope_raw.partition(":")
+ source_ids = [sid.strip()] if sid.strip() else []
+ path_prefix = [seg for seg in path_str.split("/") if seg]
+ else:
+ source_ids = [scope_raw]
+
+ user_home = getattr(self.workspace, "user_home", None)
+ results: list[dict] = []
+
+ # ── Workspace search (substring; existing semantics) ─────────
+ if search_workspace:
+ try:
+ ws_meta = self.workspace.get_metadata()
+ if ws_meta:
+ ws_hits = ws_meta.search_tables(query, limit=min(limit, 50))
+ for hit in ws_hits:
+ results.append({
+ "source": "workspace",
+ "name": hit["name"],
+ "description": (hit.get("description") or "")[:120],
+ "matched_columns": hit.get("matched_columns", []),
+ "status": "imported",
+ })
+ except Exception:
+ logger.debug("find_data: workspace search failed", exc_info=True)
+
+ # ── Catalog cache search (regex) ─────────────────────────────
+ if source_ids != [] and user_home:
+ try:
+ imported_names = {r["name"] for r in results}
+ cache_hits = search_catalog_cache(
+ user_home,
+ query,
+ source_ids=source_ids,
+ limit_per_source=min(limit, 50),
+ exclude_tables=imported_names,
+ exclude_pattern=exclude,
+ fields=fields,
+ path_prefix=path_prefix,
+ )
+ for hit in cache_hits[:limit]:
+ results.append({
+ "source": hit.get("source_id", "connected"),
+ "source_id": hit.get("source_id", ""),
+ "table_key": hit.get("table_key", ""),
+ "name": hit["name"],
+ "description": (hit.get("description") or "")[:120],
+ "matched_columns": hit.get("matched_columns", []),
+ "status": "not imported",
+ })
+ except CatalogSearchError as exc:
+ return {"error": str(exc)}
+ except Exception:
+ logger.debug("find_data: catalog search failed", exc_info=True)
- def _tool_read_candidate_metadata(self, args):
- """Read detailed metadata for a specific table from a connected source."""
+ if not results:
+ try:
+ from data_formulator.datalake.catalog_cache import list_cached_sources
+ known = sorted(list_cached_sources(user_home) or []) if user_home else []
+ except Exception:
+ known = []
+ return {
+ "results": [],
+ "valid_source_ids": known,
+ "note": (
+ f"No tables matched query={query!r} scope={scope_raw!r}. "
+ "Try a broader pattern, alternation (a|b), or list_data to browse."
+ ),
+ }
+
+ return {"results": results[:limit], "query": query, "scope": scope_raw}
+
+ def _tool_describe_data(self, args):
+ """Read detailed metadata for one table. Delegates to context handler."""
from data_formulator.agents.context import handle_read_catalog_metadata
source_id = args.get("source_id", "")
table_key = args.get("table_key", "")
@@ -909,13 +1084,37 @@ def _tool_read_candidate_metadata(self, args):
return {"result": text}
def _tool_propose_load_plan(self, args):
- """Produce a structured load plan action for frontend rendering."""
- candidates = [
- self._normalize_load_plan_candidate(c)
- for c in (args.get("candidates", []) or [])
- if isinstance(c, dict)
- ]
+ """Produce a structured load plan action for frontend rendering.
+
+ Candidates are validated against the cached catalog before they leave
+ this turn. If *every* candidate fails to resolve, we return a
+ recoverable error so the model can retry with corrected IDs instead
+ of emitting a card the user can't actually use.
+ """
+ raw = [c for c in (args.get("candidates", []) or []) if isinstance(c, dict)]
+ candidates = [self._normalize_load_plan_candidate(c) for c in raw]
reasoning = args.get("reasoning", "")
+
+ resolvable = [c for c in candidates if not c.get("resolution_error")]
+ if candidates and not resolvable:
+ # All candidates failed. Hand the model the valid IDs and ask it
+ # to retry. Returning an "error" here keeps the assistant loop
+ # alive; the frontend never sees a broken card.
+ hint = self._format_valid_sources_hint()
+ failures = "; ".join(
+ f"{c.get('source_id')!r}/{c.get('table_key')!r}: {c.get('resolution_error')}"
+ for c in candidates
+ )
+ return {
+ "error": (
+ "All proposed candidates failed to resolve against the catalog. "
+ f"Errors: {failures}. "
+ "Re-run search_data_candidates and read_candidate_metadata, then "
+ "call propose_load_plan again with the exact source_id and "
+ f"table_key from those tools.\n\n{hint}"
+ )
+ }
+
actions = [{
"type": "load_plan",
"candidates": candidates,
@@ -929,11 +1128,34 @@ def _normalize_load_plan_candidate(self, candidate):
The model sees catalog names and stable table keys, but each loader may
require a different opaque import id. Superset, for example, must be
loaded by numeric dataset_id, not by the Chinese dataset label.
+
+ If ``source_id`` is not a known cached source or ``table_key`` does
+ not match any catalog entry, a ``resolution_error`` field is set so
+ the caller can fail loudly (rather than emit a card that 500s when
+ the user clicks Load).
"""
result = dict(candidate)
source_id = str(result.get("source_id") or "")
table_key = str(result.get("table_key") or "")
+
+ resolution_error = None
+ known_sources = self._known_source_ids()
+ if not source_id:
+ resolution_error = "missing source_id"
+ elif known_sources and source_id not in known_sources:
+ resolution_error = (
+ f"unknown source_id {source_id!r}; "
+ f"valid: {', '.join(sorted(known_sources)) or 'none'}"
+ )
+
catalog_entry = self._lookup_catalog_entry(source_id, table_key)
+ if resolution_error is None and not catalog_entry:
+ if not table_key:
+ resolution_error = "missing table_key"
+ else:
+ resolution_error = (
+ f"table_key {table_key!r} not found in source {source_id!r}"
+ )
metadata = (catalog_entry or {}).get("metadata") or {}
display_name = (
@@ -963,9 +1185,30 @@ def _normalize_load_plan_candidate(self, candidate):
result["source_table"] = str(import_id)
result["source_table_name"] = str(source_name)
result["filters"] = self._normalize_load_plan_filters(result.get("filters"))
+ if resolution_error:
+ result["resolution_error"] = resolution_error
result.pop("row_limit", None)
return result
+ def _known_source_ids(self):
+ """Return the set of cached source_ids the agent can legitimately use."""
+ try:
+ user_home = getattr(self.workspace, "user_home", None)
+ if not user_home:
+ return set()
+ from data_formulator.datalake.catalog_cache import list_cached_sources
+ return set(list_cached_sources(user_home) or [])
+ except Exception:
+ logger.debug("Could not list cached sources", exc_info=True)
+ return set()
+
+ def _format_valid_sources_hint(self) -> str:
+ """Compact directory of valid source_ids for the model retry path."""
+ known = self._known_source_ids()
+ if not known:
+ return "No connected sources are currently cached."
+ return "Valid source_ids: " + ", ".join(sorted(known))
+
def _lookup_catalog_entry(self, source_id, table_key):
if not source_id or not table_key:
return None
@@ -1066,16 +1309,8 @@ def _build_system_prompt(self, last_user_text: str = ""):
message_code="TABLE_LIST_FAILED",
)
- connector_summary = "none"
- try:
- user_home = getattr(self.workspace, "user_home", None)
- if user_home:
- from data_formulator.datalake.catalog_cache import list_cached_sources
- sources = list_cached_sources(user_home)
- if sources:
- connector_summary = ", ".join(sources)
- except Exception:
- logger.debug("Could not list cached sources for prompt", exc_info=True)
+ user_home = getattr(self.workspace, "user_home", None)
+ connector_summary = _build_connector_summary_block(user_home)
from datetime import datetime
current_time = datetime.now().strftime("%Y-%m-%d %H:%M (%A)")
diff --git a/py-src/data_formulator/agents/agent_data_rec.py b/py-src/data_formulator/agents/agent_data_rec.py
index af7981e0..8bd9f054 100644
--- a/py-src/data_formulator/agents/agent_data_rec.py
+++ b/py-src/data_formulator/agents/agent_data_rec.py
@@ -4,8 +4,10 @@
import json
import time
-from data_formulator.agents.agent_utils import extract_json_objects, extract_code_from_gpt_response, generate_data_summary, supplement_missing_block, ensure_output_variable_in_code
+from data_formulator.agent_config import reasoning_effort_for
+from data_formulator.agents.agent_utils import extract_json_objects, extract_code_from_gpt_response, generate_data_summary, supplement_missing_block, ensure_output_variable_in_code, compose_system_prompt
from data_formulator.agents.agent_diagnostics import AgentDiagnostics
+from data_formulator.datalake.parquet_utils import df_to_safe_records
from data_formulator.security.sanitize import sanitize_error_message
import pandas as pd
@@ -14,108 +16,15 @@
logger = logging.getLogger(__name__)
-# =============================================================================
-# Shared prompt sections (imported by DataTransformationAgent)
-# =============================================================================
-
-SHARED_ENVIRONMENT = '''**About the execution environment:**
-- You can use BOTH DuckDB SQL and pandas operations in the same script
-- The script will run in the workspace data directory (all data files are in the current directory)
-- Each table in [CONTEXT] has a **file path** (e.g., `student_exam.parquet`, `sales.csv`). Use EXACTLY that path to load data:
- - `.parquet`: `pd.read_parquet('file.parquet')` or DuckDB `read_parquet('file.parquet')`
- - `.csv`: `pd.read_csv('file.csv')` or DuckDB `read_csv_auto('file.csv')`
- - `.json`: `pd.read_json('file.json')`
- - `.xlsx`/`.xls`: `pd.read_excel('file.xlsx')`
- - `.txt`: `pd.read_csv('file.txt', sep='\\t')`
-- **IMPORTANT:** Use the exact filename from the context — do NOT change the file extension or assume all files are parquet.
-- **Allowed libraries:** pandas, numpy, duckdb, math, datetime, json, statistics, collections, re, sklearn, scipy, random, itertools, functools, operator, time
-- **Not allowed:** matplotlib, plotly, seaborn, requests, subprocess, os, sys, io, or any other library not listed above.
-- File system access (open, write) and network access are also forbidden.
-
-**When to use DuckDB vs pandas:**
-- **Prefer plain pandas** for most tasks — it's simpler and more readable.
-- Only use DuckDB when the dataset is very large and you need efficient SQL aggregations, filtering, joins, or window functions.
-- You can combine both: DuckDB for initial loading/filtering on large files, then pandas for complex operations.
-
-**Code structure:** standalone script (no function wrapper), imports at top. **CRITICAL:** The final result DataFrame MUST be assigned to the exact variable name you specified in `"output_variable"` in the JSON spec — the system uses this name to extract the result. For example, if your output_variable is `sales_by_region`, the script must contain `sales_by_region = ...`.'''
-
-
-SHARED_SEMANTIC_TYPE_REFERENCE = '''**[SEMANTIC TYPE REFERENCE]**
-
-Choose the most specific type that fits. Only annotate fields used in chart encodings.
-
-| Category | Types |
-|---|---|
-| Temporal | DateTime, Date, Time, Timestamp, Year, Quarter, Month, Week, Day, Hour, YearMonth, YearQuarter, YearWeek, Decade, Duration |
-| Monetary measures | Amount, Price |
-| Physical measures | Quantity, Temperature |
-| Proportion | Percentage |
-| Signed/diverging | Profit, PercentageChange, Sentiment, Correlation |
-| Generic measures | Count, Number |
-| Discrete numeric | Rank, Score |
-| Identifier | ID |
-| Geographic | Latitude, Longitude, Country, State, City, Region, Address, ZipCode |
-| Entity names | Category, Name |
-| Coded categorical | Status, Boolean, Direction |
-| Binned ranges | Range |
-| Fallback | Unknown |
-
-Key guidelines:
-- Use **Amount** for summed monetary totals, **Price** for per-unit prices, **Profit** for values that can be negative.
-- Use **Temperature** (not Quantity) for temperature — it has special diverging behavior.
-- Use **Year** (not Number) for columns like "year" with values 2020, 2021.'''
-
-
-SHARED_CHART_REFERENCE = '''**[CHART TYPE REFERENCE]**
-
-| chart_type | encodings | config |
-|---|---|---|
-| Scatter Plot | x, y, color, size, facet | opacity (0.1–1.0) |
-| Regression | x, y, color, size, facet | regressionMethod ("linear","log","exp","pow","quad","poly"), polyOrder (2–10) |
-| Bar Chart | x, y, color, facet | — |
-| Grouped Bar Chart | x, y, group, facet | — |
-| Line Chart | x, y, color, strokeDash, facet | interpolate ("linear","monotone","step") |
-| Area Chart | x, y, color, facet | — |
-| Heatmap | x, y, color, facet | colorScheme ("viridis","blues","reds","oranges","greens","blueorange","redblue") |
-| Boxplot | x, y, color, facet | — |
-| Pie Chart | size, color, facet | innerRadius (0–100; 0=pie, >0=donut) |
-| Lollipop Chart | x, y, color, facet | — |
-| Waterfall Chart | x, y, color, facet | — |
-| Candlestick Chart | x, open, high, low, close, facet | — |
-| World Map | longitude, latitude, color, size | projection ("mercator","equalEarth","naturalEarth1","orthographic"), projectionCenter ([lon,lat]) |
-| US Map | longitude, latitude, color, size | — (fixed albersUsa) |
-
-**Critical chart rules:**
-- **Scatter Plot**: good default for relationships/correlations. Use config opacity (0.1–1.0) for dense data instead of encoding opacity.
-- **Regression**: automatically overlays a trend line — do NOT compute regression in Python. Use color to get separate trend lines per group.
-- **Bar Chart**: x=categorical, y=quantitative (vertical bars). Swap x↔y for horizontal bars. For histograms/distributions, bin the data in the Python step. Same-x rows are auto-stacked.
-- **Grouped Bar Chart**: use the group channel (not color) for side-by-side bars.
-- **Line Chart**: use strokeDash to differentiate line styles (e.g. actual vs forecast).
-- **Pie Chart**: use "size" channel (not "theta") for the wedge values. Avoid when >7–8 categories.
-- **Lollipop Chart**: like bar but with dot+line — cleaner for ranked comparisons.
-- **Waterfall Chart**: cumulative gain/loss — each bar starts where the previous ended.
-- **Candlestick Chart**: OHLC financial data — requires open, high, low, close columns.
-- **World Map/US Map**: use "longitude"/"latitude" as channel names, not "x"/"y".
-- **facet**: available for all chart types; use a categorical field with small cardinality.
-- All fields in "encodings" must also appear in "output_fields". Typically use 2–3 channels (x, y, color/size).'''
-
-
-SHARED_STATISTICAL_ANALYSIS = '''**Statistical analysis guide:**
-- **Regression**: use chart_type "Regression" — the trend line is automatic, do NOT compute regression values in Python code. Configure method via `{"regressionMethod": "linear"}` (options: "linear", "log", "exp", "pow", "quad", "poly"; for poly add `{"polyOrder": 3}`).
-- **Forecasting**: compute predicted future values in Python. Use Line Chart with strokeDash to distinguish actual vs forecast, and color for series grouping.
-- **Clustering**: compute cluster assignments in Python. Output [x, y, cluster_id]. Use Scatter Plot with color → cluster_id.'''
-
-
-SHARED_DUCKDB_NOTES = '''**DuckDB notes:**
-- Escape single quotes with '' (not \\')
-- No Unicode escapes (\\u0400); use character ranges directly: [а-яА-Я]
-- Cast date columns explicitly: `CAST(col AS DATE)`, `CAST(col AS TIMESTAMP)`
-- For complex datetime operations, load data first then use pandas datetime functions
-- Critical identifier quoting rule:
- * If a table/column name contains non-ASCII characters (e.g., Chinese, Japanese, Korean, Cyrillic, etc.), spaces, or punctuation,
- you MUST wrap it in double quotes, e.g. SELECT "金额" FROM "客户表".
- * Never output placeholder identifiers like your_table_name, your_column, your_condition.'''
+_AGENT_ID = "data_rec"
+from data_formulator.agents.chart_creation_guide import (
+ SHARED_ENVIRONMENT,
+ SHARED_SEMANTIC_TYPE_REFERENCE,
+ SHARED_CHART_REFERENCE,
+ SHARED_STATISTICAL_ANALYSIS,
+ SHARED_DUCKDB_NOTES,
+)
# =============================================================================
# DataRecAgent system prompt
@@ -193,29 +102,18 @@ def __init__(self, client, workspace, system_prompt=None, agent_coding_rules="",
if system_prompt is not None:
self._base_prompt = system_prompt
- self.system_prompt = system_prompt
else:
self._base_prompt = SYSTEM_PROMPT
- base_prompt = SYSTEM_PROMPT
- if combined_rules:
- self.system_prompt = base_prompt + "\n\n[AGENT CODING RULES]\nPlease follow these rules when generating code. Note: if the user instruction conflicts with these rules, you should prioritize user instructions.\n\n" + combined_rules
- else:
- self.system_prompt = base_prompt
-
- if language_instruction:
- # Insert early (after role definition, before technical sections)
- # so the LLM's "last impression" remains chart/code rules,
- # reducing recency-bias interference on chart-type selection.
- marker = "**About the execution environment:**"
- idx = self.system_prompt.find(marker)
- if idx > 0:
- self.system_prompt = (
- self.system_prompt[:idx]
- + language_instruction + "\n\n"
- + self.system_prompt[idx:]
- )
- else:
- self.system_prompt = self.system_prompt + "\n\n" + language_instruction
+
+ # Insert language instruction early (after role definition, before technical
+ # sections) so the LLM's "last impression" remains chart/code rules,
+ # reducing recency-bias interference on chart-type selection.
+ self.system_prompt = compose_system_prompt(
+ self._base_prompt,
+ agent_coding_rules=combined_rules if system_prompt is None else "",
+ language_instruction=language_instruction,
+ language_marker="**About the execution environment:**",
+ )
self._diag = AgentDiagnostics(
agent_name="DataRecAgent",
@@ -349,7 +247,7 @@ def process_gpt_response(self, input_tables, messages, response, t_llm=None):
"status": "ok",
"code": code,
"content": {
- 'rows': json.loads(query_output.to_json(orient='records')),
+ 'rows': df_to_safe_records(query_output),
'virtual': {
'table_name': output_table_name,
'row_count': row_count
@@ -461,7 +359,7 @@ def run(self, input_tables, description, n=1, prev_messages: list[dict] = [], pr
{"role":"user","content": user_query}]
t_llm_start = time.time()
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
t_llm = time.time() - t_llm_start
candidates = self.process_gpt_response(input_tables, messages, response, t_llm=t_llm)
@@ -496,7 +394,7 @@ def followup(self, input_tables, dialog, latest_data_sample, new_instruction: st
"content": f"This is the result from the latest transformation:\n\n{sample_data_str}\n\nUpdate the Python script above based on the following instruction:\n\n{new_instruction}"}]
t_llm_start = time.time()
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
t_llm = time.time() - t_llm_start
return self.process_gpt_response(input_tables, messages, response, t_llm=t_llm)
diff --git a/py-src/data_formulator/agents/agent_data_transform.py b/py-src/data_formulator/agents/agent_data_transform.py
index 59be8730..bdd842d2 100644
--- a/py-src/data_formulator/agents/agent_data_transform.py
+++ b/py-src/data_formulator/agents/agent_data_transform.py
@@ -4,16 +4,17 @@
import json
import time
-from data_formulator.agents.agent_utils import extract_json_objects, extract_code_from_gpt_response, supplement_missing_block, ensure_output_variable_in_code
+from data_formulator.agent_config import reasoning_effort_for
+from data_formulator.agents.agent_utils import extract_json_objects, extract_code_from_gpt_response, supplement_missing_block, ensure_output_variable_in_code, compose_system_prompt
from data_formulator.agents.agent_diagnostics import AgentDiagnostics
+from data_formulator.datalake.parquet_utils import df_to_safe_records
from data_formulator.security.sanitize import sanitize_error_message
-from data_formulator.agents.agent_data_rec import (
+from data_formulator.agents.chart_creation_guide import (
SHARED_ENVIRONMENT,
SHARED_SEMANTIC_TYPE_REFERENCE,
SHARED_CHART_REFERENCE,
SHARED_STATISTICAL_ANALYSIS,
SHARED_DUCKDB_NOTES,
-
)
import pandas as pd
@@ -21,6 +22,8 @@
logger = logging.getLogger(__name__)
+_AGENT_ID = "data_transform"
+
SYSTEM_PROMPT = f'''You are a data scientist who transforms data for visualization.
Given [CONTEXT] (dataset summaries) and [GOAL] (user intent + chart spec), refine the goal and write a Python script to produce the transformed data.
@@ -99,26 +102,15 @@ def __init__(self, client, workspace, system_prompt=None, agent_coding_rules="",
if system_prompt is not None:
self._base_prompt = system_prompt
- self.system_prompt = system_prompt
else:
self._base_prompt = SYSTEM_PROMPT
- base_prompt = SYSTEM_PROMPT
- if combined_rules:
- self.system_prompt = base_prompt + "\n\n[AGENT CODING RULES]\nPlease follow these rules when generating code. Note: if the user instruction conflicts with these rules, you should prioritize user instructions.\n\n" + combined_rules
- else:
- self.system_prompt = base_prompt
-
- if language_instruction:
- marker = "**About the execution environment:**"
- idx = self.system_prompt.find(marker)
- if idx > 0:
- self.system_prompt = (
- self.system_prompt[:idx]
- + language_instruction + "\n\n"
- + self.system_prompt[idx:]
- )
- else:
- self.system_prompt = self.system_prompt + "\n\n" + language_instruction
+
+ self.system_prompt = compose_system_prompt(
+ self._base_prompt,
+ agent_coding_rules=combined_rules if system_prompt is None else "",
+ language_instruction=language_instruction,
+ language_marker="**About the execution environment:**",
+ )
self._diag = AgentDiagnostics(
agent_name="DataTransformationAgent",
@@ -250,7 +242,7 @@ def process_gpt_response(self, response, messages, t_llm=None):
"status": "ok",
"code": code,
"content": {
- 'rows': json.loads(query_output.to_json(orient='records')),
+ 'rows': df_to_safe_records(query_output),
'virtual': {
'table_name': output_table_name,
'row_count': row_count
@@ -383,16 +375,16 @@ def run(self, input_tables, description, prev_messages: list[dict] = [], n=1,
{"role":"user","content": user_content}]
t_llm_start = time.time()
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
t_llm = time.time() - t_llm_start
except Exception as e:
# Fallback to text-only if model doesn't support images
logger.warning(f"Image-based completion failed, falling back to text-only: {e}")
- messages = [{"role":"system", "content": self.system_prompt},
+ messages = [{'role':'system', 'content': self.system_prompt},
*filtered_prev_messages,
- {"role":"user","content": user_query}]
+ {'role':'user','content': user_query}]
t_llm_start = time.time()
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
t_llm = time.time() - t_llm_start
candidates = self.process_gpt_response(response, messages, t_llm=t_llm)
@@ -454,14 +446,14 @@ def followup(self, input_tables, dialog, latest_data_sample, new_instruction: st
messages = [*updated_dialog, {"role":"user", "content": user_content}]
t_llm_start = time.time()
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
t_llm = time.time() - t_llm_start
except Exception as e:
# Fallback to text-only if model doesn't support images
logger.warning(f"Image-based completion failed, falling back to text-only: {e}")
- messages = [*updated_dialog, {"role":"user", "content": followup_text}]
+ messages = [*updated_dialog, {'role':'user', 'content': followup_text}]
t_llm_start = time.time()
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
t_llm = time.time() - t_llm_start
candidates = self.process_gpt_response(response, messages, t_llm=t_llm)
diff --git a/py-src/data_formulator/agents/agent_experience_distill.py b/py-src/data_formulator/agents/agent_experience_distill.py
index ccf9c5c3..cc738495 100644
--- a/py-src/data_formulator/agents/agent_experience_distill.py
+++ b/py-src/data_formulator/agents/agent_experience_distill.py
@@ -20,13 +20,13 @@
from datetime import datetime, timezone
from typing import Any
-import litellm
-import openai
-
+from data_formulator.agent_config import reasoning_effort_for
from data_formulator.agents.client_utils import Client
logger = logging.getLogger(__name__)
+_AGENT_ID = "experience_distill"
+
SYSTEM_PROMPT = """\
You are a knowledge distiller. Given the chronological events of a data
@@ -386,26 +386,9 @@ def _render_events(cls, events: list[Any]) -> str:
def _call_llm(self, messages: list[dict]) -> str:
"""Single LLM call to generate the experience document."""
- if self.client.endpoint == "openai":
- client = openai.OpenAI(
- base_url=self.client.params.get("api_base"),
- api_key=self.client.params.get("api_key", ""),
- timeout=self.timeout_seconds,
- )
- resp = client.chat.completions.create(
- model=self.client.model,
- messages=messages,
- )
- else:
- params = self.client.params.copy()
- params.setdefault("timeout", self.timeout_seconds)
- resp = litellm.completion(
- model=self.client.model,
- messages=messages,
- drop_params=True,
- **params,
- )
-
+ resp = self.client.get_completion(
+ messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model), timeout=self.timeout_seconds,
+ )
return resp.choices[0].message.content or ""
@staticmethod
diff --git a/py-src/data_formulator/agents/agent_interactive_explore.py b/py-src/data_formulator/agents/agent_interactive_explore.py
index dd4c81fa..67847ec2 100644
--- a/py-src/data_formulator/agents/agent_interactive_explore.py
+++ b/py-src/data_formulator/agents/agent_interactive_explore.py
@@ -7,10 +7,13 @@
import pandas as pd
-import litellm
-import openai
-
-from data_formulator.agents.agent_utils import extract_json_objects, generate_data_summary
+from data_formulator.agent_config import reasoning_effort_for
+from data_formulator.agents.agent_utils import (
+ attach_reasoning_content,
+ extract_json_objects,
+ generate_data_summary,
+)
+from data_formulator.agents.agent_language import inject_language_instruction
from data_formulator.agents.context import (
build_focused_thread_context,
build_lightweight_table_context,
@@ -20,6 +23,8 @@
logger = logging.getLogger(__name__)
+_AGENT_ID = "interactive_explore"
+
# ── Tool definition (inspect only) ────────────────────────────────────────
INSPECT_TOOL = {
@@ -184,8 +189,7 @@ def run(self, input_tables, start_question=None,
if self._knowledge_store:
system_prompt += self._knowledge_store.format_rules_block()
- if self.language_instruction:
- system_prompt = system_prompt + "\n\n" + self.language_instruction
+ system_prompt = inject_language_instruction(system_prompt, self.language_instruction)
ctx_elapsed = time.time() - t_ctx
logger.info(
@@ -222,7 +226,7 @@ def run(self, input_tables, start_question=None,
# ── Stream the final response ─────────────────────────────────
try:
- stream = self.client.get_completion(messages=messages, stream=True)
+ stream = self.client.get_completion(messages=messages, stream=True, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
except Exception as e:
# If image fails, retry without it
if current_chart:
@@ -303,6 +307,7 @@ def _run_inspect_round(self, messages, input_tables):
for tc in tool_calls
],
}
+ attach_reasoning_content(assistant_msg, choice.message)
messages.append(assistant_msg)
# Execute each tool call
@@ -333,45 +338,6 @@ def _run_inspect_round(self, messages, input_tables):
def _call_llm_with_tools(self, messages, tools):
"""Non-streaming LLM call with tool definitions."""
- if self.client.endpoint == "openai":
- client = openai.OpenAI(
- base_url=self.client.params.get("api_base", None),
- api_key=self.client.params.get("api_key", ""),
- timeout=120,
- )
- try:
- return client.chat.completions.create(
- model=self.client.model,
- messages=messages,
- tools=tools,
- )
- except Exception as e:
- if self.client._is_image_deserialize_error(str(e)):
- sanitized = self.client._strip_images_from_messages(messages)
- return client.chat.completions.create(
- model=self.client.model,
- messages=sanitized,
- tools=tools,
- )
- raise
- else:
- params = self.client.params.copy()
- try:
- return litellm.completion(
- model=self.client.model,
- messages=messages,
- tools=tools,
- drop_params=True,
- **params,
- )
- except Exception as e:
- if self.client._is_image_deserialize_error(str(e)):
- sanitized = self.client._strip_images_from_messages(messages)
- return litellm.completion(
- model=self.client.model,
- messages=sanitized,
- tools=tools,
- drop_params=True,
- **params,
- )
- raise
\ No newline at end of file
+ return self.client.get_completion_with_tools(
+ messages, tools=tools, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model),
+ )
\ No newline at end of file
diff --git a/py-src/data_formulator/agents/agent_language.py b/py-src/data_formulator/agents/agent_language.py
index 38627d76..e32fe016 100644
--- a/py-src/data_formulator/agents/agent_language.py
+++ b/py-src/data_formulator/agents/agent_language.py
@@ -112,9 +112,12 @@ def build_language_instruction(language: str, *, mode: str = "full") -> str:
``"full"`` – detailed field-level rules (for text-heavy agents).
``"compact"`` – minimal instruction (for code-generation agents).
- Returns ``""`` when *language* is ``"en"`` (or empty / unrecognised).
+ Returns ``""`` when *language* is ``"en"``, or when it is empty /
+ whitespace-only (which normalises to the default language, English).
+ For unrecognised codes (e.g. ``"xx"``), a non-empty instruction block
+ is still returned using the raw code as the display name.
"""
- lang = (language or DEFAULT_LANGUAGE).strip().lower()
+ lang = ((language or "").strip().lower()) or DEFAULT_LANGUAGE.lower()
if lang == "en":
return ""
diff --git a/py-src/data_formulator/agents/agent_report_gen.py b/py-src/data_formulator/agents/agent_report_gen.py
index 06749fa7..9d936b28 100644
--- a/py-src/data_formulator/agents/agent_report_gen.py
+++ b/py-src/data_formulator/agents/agent_report_gen.py
@@ -17,11 +17,15 @@
import logging
from typing import Any, Generator
-import litellm
-import openai
import pandas as pd
-from data_formulator.agents.agent_utils import generate_data_summary
+from data_formulator.agent_config import reasoning_effort_for
+from data_formulator.agents.agent_utils import (
+ attach_reasoning_content,
+ generate_data_summary,
+)
+from data_formulator.agents.agent_language import inject_language_instruction
+from data_formulator.datalake.parquet_utils import df_to_safe_records
from data_formulator.agents.context import (
build_focused_thread_context,
build_lightweight_table_context,
@@ -38,6 +42,8 @@
logger = logging.getLogger(__name__)
+_AGENT_ID = "report_gen"
+
# ── Tool definitions ──────────────────────────────────────────────────────
INSPECT_TOOLS = [
@@ -90,7 +96,11 @@
# ── System prompt ─────────────────────────────────────────────────────────
SYSTEM_PROMPT = """\
-You are a data journalist who creates concise, insightful reports based on data explorations.
+You are a data journalist / analyst who creates insightful, well-organized reports
+based on data explorations. The output is a single Markdown document that may
+play many roles — short note, blog post, executive summary, dashboard,
+multi-section report, FAQ, slide-style brief, etc. Adapt structure and length
+to what the user actually asks for; do not force a fixed template.
The user message contains context about the workspace:
- **[PRIMARY TABLE(S)]** / **[OTHER AVAILABLE TABLES]**: Lightweight schema of datasets.
@@ -99,33 +109,54 @@
- **[AVAILABLE CHARTS]**: List of charts with their type, encodings, and table references.
## Phase 1 — Inspect
-Before writing, use `inspect_chart` and `inspect_source_data` to gather information about the charts and data you want to include. You don't need to inspect everything — focus on what's relevant to the user's request.
+Before writing, use `inspect_chart` and `inspect_source_data` to gather information
+about the charts and data you want to include. Inspect only what you actually need
+to ground your narrative — don't fetch everything.
## Phase 2 — Write the report
-Write a concise report (under 200 words, ~1 minute read).
+### Embedding charts (REQUIRED FORMAT — do not change this)
To embed a chart image, use markdown image syntax with a `chart://` URL:

Example: ``
-The chart_id must match one from [AVAILABLE CHARTS]. Place each chart embed on its own line.
+The chart_id must match one from [AVAILABLE CHARTS]. Place each chart embed on
+its own line (it renders as a block). You can embed the same chart at most
+once. Captions are short — one line describing what the chart shows.
-For data tables, just write standard markdown tables directly:
+### Tables
+For data tables, write standard markdown tables directly:
| date | value |
| --- | --- |
| 2020-01 | -43.5 |
-Guidelines:
-- Start with a `# Title`
-- Connect findings into a coherent narrative
-- For each chart, briefly explain what it shows and the key insight
-- Use chart embeds at appropriate places
-- Use markdown tables when you want to show specific data points
-- End with a **In summary:** paragraph
-- Write in markdown, be concise, respect facts in the data
-- Adapt your style to the user's request (blog, executive summary, casual, etc.)
-- Do NOT make up facts or judgements beyond what the data shows
+### Style & structure — adapt to the user's request
+The user may ask for any of:
+- a short note or social-style summary (a few sentences, maybe one chart),
+- a blog post / narrative report (intro → findings → takeaway),
+- an executive summary (key numbers up top, then context),
+- a KPI dashboard / multi-section overview (headings per topic, multiple charts
+ arranged with short commentary between them),
+- a slide-style brief (compact sections with bullet points and embedded charts),
+- a deeper analytical report with sub-sections, methodology notes, and caveats.
+
+Pick the structure that fits the request and the available material. Reasonable
+defaults if the user is vague:
+- Start with a `# Title` that reflects the topic.
+- Group related findings under `##` (and `###` if useful) headings.
+- Around each embedded chart, briefly explain what it shows and the key insight.
+- Use bullets / short paragraphs / tables where they help; don't pad.
+- Close with a brief takeaway or summary section if the report is more than a
+ few paragraphs. For very short outputs (notes, single-chart blurbs), a closing
+ summary is optional.
+
+### Guardrails
+- Write in Markdown. Keep prose tight; let the data and charts carry the weight.
+- Stay faithful to the data — do not invent numbers, comparisons, or causation
+ that the data does not actually support.
+- It is fine to flag uncertainty ("based on the sample shown…") when appropriate.
+- Embed every chart you discuss; don't reference a chart in prose without showing it.
"""
@@ -183,8 +214,7 @@ def run(
# Build system prompt
system_prompt = SYSTEM_PROMPT
- if self.language_instruction:
- system_prompt += "\n\n" + self.language_instruction
+ system_prompt = inject_language_instruction(system_prompt, self.language_instruction)
messages: list[dict] = [
{"role": "system", "content": system_prompt},
@@ -251,6 +281,7 @@ def _run_inspect_phase(
for tc in tool_calls
],
}
+ attach_reasoning_content(assistant_msg, choice.message)
messages.append(assistant_msg)
# Execute each tool
@@ -398,7 +429,7 @@ def _resolve_table_data(
df = df.head(max_rows)
return {
"columns": df.columns.tolist(),
- "rows": df.to_dict(orient="records"),
+ "rows": df_to_safe_records(df),
}
except Exception as e:
logger.error(f"[ReportAgent] resolve_table_data error: {e}")
@@ -410,84 +441,16 @@ def _resolve_table_data(
def _call_llm(self, messages: list[dict], tools: list[dict] | None = None):
"""Non-streaming LLM call with optional tool definitions."""
- if self.client.endpoint == "openai":
- client = openai.OpenAI(
- base_url=self.client.params.get("api_base", None),
- api_key=self.client.params.get("api_key", ""),
- timeout=120,
+ if tools:
+ return self.client.get_completion_with_tools(
+ messages, tools=tools, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model),
)
- kwargs: dict[str, Any] = {
- "model": self.client.model,
- "messages": messages,
- }
- if tools:
- kwargs["tools"] = tools
- try:
- return client.chat.completions.create(**kwargs)
- except Exception as e:
- if self.client._is_image_deserialize_error(str(e)):
- sanitized = self.client._strip_images_from_messages(messages)
- kwargs["messages"] = sanitized
- return client.chat.completions.create(**kwargs)
- raise
- else:
- params = self.client.params.copy()
- kwargs = {
- "model": self.client.model,
- "messages": messages,
- "drop_params": True,
- }
- if tools:
- kwargs["tools"] = tools
- kwargs.update(params)
- try:
- return litellm.completion(**kwargs)
- except Exception as e:
- if self.client._is_image_deserialize_error(str(e)):
- sanitized = self.client._strip_images_from_messages(messages)
- kwargs["messages"] = sanitized
- return litellm.completion(**kwargs)
- raise
+ return self.client.get_completion(messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
def _call_llm_streaming(self, messages: list[dict], tools: list[dict] | None = None):
"""Streaming LLM call with optional tool definitions."""
- if self.client.endpoint == "openai":
- client = openai.OpenAI(
- base_url=self.client.params.get("api_base", None),
- api_key=self.client.params.get("api_key", ""),
- timeout=120,
+ if tools:
+ return self.client.get_completion_with_tools(
+ messages, tools=tools, stream=True, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model),
)
- kwargs: dict[str, Any] = {
- "model": self.client.model,
- "messages": messages,
- "stream": True,
- }
- if tools:
- kwargs["tools"] = tools
- try:
- return client.chat.completions.create(**kwargs)
- except Exception as e:
- if self.client._is_image_deserialize_error(str(e)):
- sanitized = self.client._strip_images_from_messages(messages)
- kwargs["messages"] = sanitized
- return client.chat.completions.create(**kwargs)
- raise
- else:
- params = self.client.params.copy()
- kwargs = {
- "model": self.client.model,
- "messages": messages,
- "stream": True,
- "drop_params": True,
- }
- if tools:
- kwargs["tools"] = tools
- kwargs.update(params)
- try:
- return litellm.completion(**kwargs)
- except Exception as e:
- if self.client._is_image_deserialize_error(str(e)):
- sanitized = self.client._strip_images_from_messages(messages)
- kwargs["messages"] = sanitized
- return litellm.completion(**kwargs)
- raise
+ return self.client.get_completion(messages, stream=True, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
diff --git a/py-src/data_formulator/agents/agent_simple.py b/py-src/data_formulator/agents/agent_simple.py
index b2857fe7..c3fb16c9 100644
--- a/py-src/data_formulator/agents/agent_simple.py
+++ b/py-src/data_formulator/agents/agent_simple.py
@@ -10,11 +10,14 @@
import json
import logging
+from data_formulator.agent_config import reasoning_effort_for
from data_formulator.agents.agent_utils import extract_json_objects
from data_formulator.agents.agent_language import inject_language_instruction
logger = logging.getLogger(__name__)
+_AGENT_ID = "simple"
+
# ---------------------------------------------------------------------------
# System prompts
@@ -67,17 +70,25 @@
_CHART_INTENT_SYSTEM_PROMPT = (
"Route a chart edit request to one of two agents.\n"
"\n"
- "STYLE — refine the current chart, keeping its analytical intent.\n"
- " Uses only the fields already on the chart, plus simple derivations\n"
- " expressible in Vega-Lite transforms (filter, sort, top-N, bin,\n"
- " aggregate over an existing field, simple calculate). Also covers\n"
- " any purely visual change: theme, colors, fonts, legend, axes,\n"
- " mark size/opacity, donut hole, etc.\n"
+ "The test: does the request change the set of fields bound to chart\n"
+ "encodings (x, y, color, size, shape, row, column, facet, theta, etc.)?\n"
+ "\n"
+ "STYLE — encoding fields are unchanged. The user is refining the same\n"
+ "chart that answers the same question. This includes:\n"
+ " - filter / sort / top-N / limit (even on fields not currently encoded,\n"
+ " as long as the field already exists in the data)\n"
+ " - layering or overlay on the same encoded fields (trend line, error bars)\n"
+ " - aggregation / bin changes on an already-encoded field\n"
+ " - any visual change: theme, colors, fonts, legend, axes, mark\n"
+ " size/opacity, donut hole, tooltip text\n"
"\n"
- "DATA — a new analytical intent or a transformation beyond simple\n"
- " Vega-Lite: bring in a different field that isn't on the chart,\n"
- " add a column from another table, pivot/unpivot,joins,\n"
- " or otherwise reshape the data so it answers a different question.\n"
+ "DATA — encoding fields change, or a new field must be computed/joined:\n"
+ " - replace, add, or remove an encoded field (e.g. \"color by region\",\n"
+ " \"use quantity instead of price on y\", \"drop size\")\n"
+ " - change chart type in a way that requires different fields\n"
+ " - pivot / unpivot / reshape, bring in a field from another table\n"
+ " - compute a new derived field beyond a simple Vega-Lite calculate\n"
+ " (moving average, percentile rank, etc.)\n"
"\n"
"Requests may be in any language. Reply with one word: STYLE or DATA."
)
@@ -123,7 +134,7 @@ def nl_to_filter(self, columns: list[dict], instruction: str) -> dict:
]
logger.info("[SimpleAgents.nl_to_filter] run start")
- response = self.client.get_completion(messages=messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
raw = response.choices[0].message.content.strip()
# Strip markdown code fences if present
@@ -176,7 +187,7 @@ def workspace_name(self, table_names: list[str], user_query: str = "") -> str:
]
logger.info("[SimpleAgents.workspace_name] run start")
- response = self.client.get_completion(messages=messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
display_name = response.choices[0].message.content.strip().strip("\"'")
if len(display_name) > 60:
display_name = display_name[:57] + "..."
@@ -211,7 +222,7 @@ def classify_chart_intent(self, instruction: str) -> str:
]
try:
- response = self.client.get_completion(messages=messages)
+ response = self.client.get_completion(messages=messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
raw = (response.choices[0].message.content or "").strip().upper()
except Exception as e:
logger.warning("[SimpleAgents.classify_chart_intent] LLM call failed: %s", e)
diff --git a/py-src/data_formulator/agents/agent_sort_data.py b/py-src/data_formulator/agents/agent_sort_data.py
index f4e8b9cd..9daf82f2 100644
--- a/py-src/data_formulator/agents/agent_sort_data.py
+++ b/py-src/data_formulator/agents/agent_sort_data.py
@@ -2,6 +2,7 @@
# Licensed under the MIT License.
import json
+from data_formulator.agent_config import reasoning_effort_for
from data_formulator.agents.agent_utils import extract_json_objects
from data_formulator.agents.agent_language import inject_language_instruction
@@ -9,6 +10,8 @@
logger = logging.getLogger(__name__)
+_AGENT_ID = "sort_data"
+
SYSTEM_PROMPT = '''You are a data scientist to help user to sort data.
The user will provide list of items in the form of a json object, and your goal is to sort the data in its natural order based on your knowledge.
@@ -74,7 +77,7 @@ def run(self, name, values, n=1):
input_obj = {
'name': name,
- 'value': values
+ 'values': values
}
user_query = f"[INPUT]\n\n{json.dumps(input_obj, ensure_ascii=False)}\n\n[OUTPUT]"
@@ -90,7 +93,7 @@ def run(self, name, values, n=1):
{"role":"user","content": user_query}]
###### the part that calls open_ai
- response = self.client.get_completion(messages = messages)
+ response = self.client.get_completion(messages = messages, reasoning_effort=reasoning_effort_for(_AGENT_ID, self.client.model))
#log = {'messages': messages, 'response': response.model_dump(mode='json')}
diff --git a/py-src/data_formulator/agents/agent_utils.py b/py-src/data_formulator/agents/agent_utils.py
index 231225f0..f5bcb7e8 100644
--- a/py-src/data_formulator/agents/agent_utils.py
+++ b/py-src/data_formulator/agents/agent_utils.py
@@ -14,6 +14,98 @@
_logger = logging.getLogger(__name__)
+# ---------------------------------------------------------------------------
+# system-prompt composition
+# ---------------------------------------------------------------------------
+
+def compose_system_prompt(
+ base_prompt: str,
+ *,
+ agent_coding_rules: str = "",
+ language_instruction: str = "",
+ language_marker: str | None = None,
+) -> str:
+ """Assemble a system prompt by appending coding rules and injecting a language block.
+
+ - ``agent_coding_rules`` (already-combined rules text) is appended under an
+ ``[AGENT CODING RULES]`` preamble when non-empty.
+ - ``language_instruction`` is inserted before ``language_marker`` if the marker
+ is found in the resulting prompt, otherwise appended at the end.
+ """
+ # Local import keeps agent_utils dependency-light at module import time.
+ from data_formulator.agents.agent_language import inject_language_instruction
+
+ prompt = base_prompt
+ if agent_coding_rules:
+ prompt = prompt + (
+ "\n\n[AGENT CODING RULES]\n"
+ "Please follow these rules when generating code. "
+ "Note: if the user instruction conflicts with these rules, "
+ "you should prioritize user instructions.\n\n"
+ ) + agent_coding_rules
+ if language_instruction:
+ prompt = inject_language_instruction(
+ prompt, language_instruction, marker=language_marker
+ )
+ return prompt
+
+
+# ---------------------------------------------------------------------------
+# reasoning_content helpers
+# ---------------------------------------------------------------------------
+
+def attach_reasoning_content(msg: dict, choice_message) -> dict:
+ """Attach ``reasoning_content`` from an LLM response to an assistant message dict.
+
+ Some reasoning models (currently DeepSeek V4) return a
+ ``reasoning_content`` field alongside the regular ``content``.
+ In multi-turn conversations this field **must** be echoed back in the
+ assistant message, otherwise the API may reject the request or the
+ chain-of-thought context is lost.
+
+ For models that do not produce this field the function is a safe no-op.
+
+ Args:
+ msg: The assistant message dict (mutated in-place and returned).
+ choice_message: The ``choice.message`` object from an LLM response.
+
+ Returns:
+ The same *msg* dict, for chaining convenience.
+
+ See: https://api-docs.deepseek.com/guides/reasoning_model
+ """
+ rc = getattr(choice_message, "reasoning_content", None)
+ if rc is not None:
+ msg["reasoning_content"] = rc
+ return msg
+
+
+def accumulate_reasoning_content(
+ accumulated: str | None, delta
+) -> str | None:
+ """Accumulate ``reasoning_content`` from streaming delta chunks.
+
+ In streaming mode, reasoning models (currently DeepSeek V4) deliver
+ ``reasoning_content`` as incremental ``delta.reasoning_content``
+ chunks, similar to ``delta.content``. This helper concatenates them.
+
+ For non-reasoning models the delta has no such attribute; the
+ accumulator is returned unchanged.
+
+ Args:
+ accumulated: The string accumulated so far, or ``None``.
+ delta: A streaming ``choice.delta`` object.
+
+ Returns:
+ Updated accumulator (``str`` once the first chunk arrives,
+ ``None`` if no reasoning_content has been seen).
+ """
+ rc_delta = getattr(delta, "reasoning_content", None)
+ if rc_delta:
+ return (accumulated or "") + rc_delta
+ return accumulated
+
+
def _source_table_matches_catalog_entry(
source_table: str,
catalog_entry: dict[str, Any],
diff --git a/py-src/data_formulator/agents/chart_creation_guide.py b/py-src/data_formulator/agents/chart_creation_guide.py
new file mode 100644
index 00000000..20a6ab94
--- /dev/null
+++ b/py-src/data_formulator/agents/chart_creation_guide.py
@@ -0,0 +1,153 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+"""Chart creation guide and shared prompt fragments.
+
+This module is the canonical source of truth for the prompt fragments
+that describe how the agent should write code, choose chart types,
+annotate semantic types, run statistical analyses, and use DuckDB.
+
+The individual ``SHARED_*`` fragments are imported by ``DataRecAgent``
+and ``DataTransformationAgent`` (which weave them into their system
+prompts) and are also composed into ``CHART_CREATION_GUIDE``, the
+single block injected lazily on the first ``visualize`` tool call.
+"""
+
+
+SHARED_ENVIRONMENT = '''**About the execution environment:**
+- You can use BOTH DuckDB SQL and pandas operations in the same script
+- The script will run in the workspace data directory (all data files are in the current directory)
+- Each table in [CONTEXT] has a **file path** (e.g., `student_exam.parquet`, `sales.csv`). Use EXACTLY that path to load data:
+ - `.parquet`: `pd.read_parquet('file.parquet')` or DuckDB `read_parquet('file.parquet')`
+ - `.csv`: `pd.read_csv('file.csv')` or DuckDB `read_csv_auto('file.csv')`
+ - `.json`: `pd.read_json('file.json')`
+ - `.xlsx`/`.xls`: `pd.read_excel('file.xlsx')`
+ - `.txt`: `pd.read_csv('file.txt', sep='\\t')`
+- **IMPORTANT:** Use the exact filename from the context — do NOT change the file extension or assume all files are parquet.
+- **Allowed libraries:** pandas, numpy, duckdb, math, datetime, json, statistics, collections, re, sklearn, scipy, random, itertools, functools, operator, time
+- **Not allowed:** matplotlib, plotly, seaborn, requests, subprocess, os, sys, io, or any other library not listed above.
+- File system access (open, write) and network access are also forbidden.
+
+**When to use DuckDB vs pandas:**
+- **Prefer plain pandas** for most tasks — it's simpler and more readable.
+- Only use DuckDB when the dataset is very large and you need efficient SQL aggregations, filtering, joins, or window functions.
+- You can combine both: DuckDB for initial loading/filtering on large files, then pandas for complex operations.
+
+**Code structure:** standalone script (no function wrapper), imports at top. **CRITICAL:** The final result DataFrame MUST be assigned to the exact variable name you specified in `"output_variable"` in the JSON spec — the system uses this name to extract the result. For example, if your output_variable is `sales_by_region`, the script must contain `sales_by_region = ...`.'''
+
+
+SHARED_SEMANTIC_TYPE_REFERENCE = '''**[SEMANTIC TYPE REFERENCE]**
+
+Choose the most specific type that fits. Only annotate fields used in chart encodings.
+
+| Category | Types |
+|---|---|
+| Temporal | DateTime, Date, Time, Timestamp, Year, Quarter, Month, Week, Day, Hour, YearMonth, YearQuarter, YearWeek, Decade, Duration |
+| Monetary measures | Amount, Price |
+| Physical measures | Quantity, Temperature |
+| Proportion | Percentage |
+| Signed/diverging | Profit, PercentageChange, Sentiment, Correlation |
+| Generic measures | Count, Number |
+| Discrete numeric | Rank, Score |
+| Identifier | ID |
+| Geographic | Latitude, Longitude, Country, State, City, Region, Address, ZipCode |
+| Entity names | Category, Name |
+| Coded categorical | Status, Boolean, Direction |
+| Binned ranges | Range |
+| Fallback | Unknown |
+
+Key guidelines:
+- Use **Amount** for summed monetary totals, **Price** for per-unit prices, **Profit** for values that can be negative.
+- Use **Temperature** (not Quantity) for temperature — it has special diverging behavior.
+- Use **Year** (not Number) for columns like "year" with values 2020, 2021.'''
+
+
+SHARED_CHART_REFERENCE = '''**[CHART TYPE REFERENCE]**
+
+The `chart_type` value in the `visualize` action MUST be one of the names listed
+in the first column below (exact spelling, including capitalization). When a row
+lists multiple names, pick whichever fits the "when to use" hint best.
+
+| chart_type | encodings | config | when to use |
+|---|---|---|---|
+| Scatter Plot | x, y, color, size, facet | opacity (0.1–1.0) | Relationships between two quantitative fields |
+| Regression | x, y, color, size, facet | regressionMethod ("linear","log","exp","pow","quad","poly"), polyOrder (2–10) | Trend line over scatter; one line per color group |
+| Bar Chart / Lollipop Chart / Waterfall Chart | x, y, color, facet | — | Bar: default categorical comparison. Lollipop: cleaner for ranked lists / sparse categories. Waterfall: cumulative gain/loss, each bar starts where the previous ended |
+| Grouped Bar Chart | x, y, group, facet | — | Side-by-side bars across a second categorical dimension |
+| Histogram / Density Plot | x, color, facet | — | Distribution of one quantitative field. Histogram: discrete bins, auto-binned. Density Plot: smooth KDE curve |
+| Boxplot | x, y, color, facet | — | Distribution summary (median/quartiles/outliers) by category |
+| Ranged Dot Plot | x, y, color, facet | — | Min–max range or two-point comparison per category |
+| Line Chart | x, y, color, strokeDash, facet | interpolate ("linear","monotone","step") | Trends over an ordered (usually temporal) x-axis |
+| Area Chart | x, y, color, facet | — | Magnitude over ordered x; auto-stacks when color is set |
+| Pie Chart | size, color, facet | innerRadius (0–100; 0=pie, >0=donut) | Part-of-whole with ≤7 categories. Wedge value goes on **size**, not **theta** |
+| Radar Chart | x, y, color, facet | — | Multi-metric profile/comparison; x = metric name, y = value, color = entity (long-form data) |
+| Heatmap | x, y, color, facet | colorScheme ("viridis","blues","reds","oranges","greens","blueorange","redblue") | Matrix / 2D density; color encodes the quantitative cell value |
+| Bar Table | x, y, color, facet | — | Ranked horizontal table with inline bars; one row per category. y = category, x = value |
+| KPI Card | metric, value, goal | — | "Big number" dashboard tile(s); one row per tile. `value` must be pre-aggregated; `goal` is optional |
+| Candlestick Chart | x, open, high, low, close, facet | — | OHLC financial data |
+| World Map | longitude, latitude, color, size | projection ("mercator","equalEarth","naturalEarth1","orthographic"), projectionCenter ([lon,lat]) | Geographic points/regions on a world projection |
+| US Map | longitude, latitude, color, size | — (fixed albersUsa) | US-only points/regions (albersUsa projection) |
+
+**Critical chart rules:**
+- **Scatter Plot**: use config opacity (0.1–1.0) for dense data instead of encoding opacity.
+- **Regression**: trend line is automatic — do NOT compute regression coefficients/predictions in Python. Use `color` to get separate trend lines per group.
+- **Bar Chart**: x=categorical, y=quantitative (vertical bars). Swap x↔y for horizontal bars. Same-x rows are auto-stacked when `color` is set.
+- **Grouped Bar Chart**: use the `group` channel (not `color`) for side-by-side bars.
+- **Histogram**: do NOT pre-bin in Python — pass the raw quantitative field on `x` and the chart bins automatically. Pre-aggregating gives wrong bin widths.
+- **Line Chart**: use `strokeDash` to differentiate line styles (e.g. actual vs forecast).
+- **Pie Chart**: use the `size` channel (not `theta`) for wedge values. Avoid when >7–8 categories.
+- **Radar Chart**: data must be long-form — one row per (entity, metric, value). If your data is wide-form (one column per metric), melt it first in the Python step.
+- **Bar Table**: y is the category column to rank; x is the quantitative value driving bar length. Don't sort in Python — the template sorts.
+- **KPI Card**: channels are `metric`, `value`, `goal` (not x/y). One DataFrame row = one tile. The `value` column must already contain the final number to display (aggregate upstream in the Python step).
+- **Candlestick Chart**: requires `open`, `high`, `low`, `close` columns.
+- **World Map / US Map**: channel names are `longitude` / `latitude`, not `x` / `y`.
+- **facet**: available for nearly all chart types; use a low-cardinality categorical field.
+- All fields in `encodings` must also appear in `output_fields`. Typically use 2–3 channels (x, y, color/size).'''
+
+
+SHARED_STATISTICAL_ANALYSIS = '''**Statistical analysis guide:**
+- **Regression**: use chart_type "Regression" — the trend line is automatic, do NOT compute regression values in Python code. Configure method via `{"regressionMethod": "linear"}` (options: "linear", "log", "exp", "pow", "quad", "poly"; for poly add `{"polyOrder": 3}`).
+- **Forecasting**: compute predicted future values in Python. Use Line Chart with strokeDash to distinguish actual vs forecast, and color for series grouping.
+- **Clustering**: compute cluster assignments in Python. Output [x, y, cluster_id]. Use Scatter Plot with color → cluster_id.'''
+
+
+SHARED_DUCKDB_NOTES = '''**DuckDB notes:**
+- Escape single quotes with '' (not \\')
+- No Unicode escapes (\\u0400); use character ranges directly: [а-яА-Я]
+- Cast date columns explicitly: `CAST(col AS DATE)`, `CAST(col AS TIMESTAMP)`
+- For complex datetime operations, load data first then use pandas datetime functions
+- Critical identifier quoting rule:
+ * If a table/column name contains non-ASCII characters (e.g., Chinese, Japanese, Korean, Cyrillic, etc.), spaces, or punctuation,
+ you MUST wrap it in double quotes, e.g. SELECT "金额" FROM "客户表".
+ * Never output placeholder identifiers like your_table_name, your_column, your_condition.'''
+
+
+CHART_CREATION_GUIDE = f"""\
+## Chart Creation Guide
+
+The following reference material applies when you call the `visualize` tool.
+
+### A. Code Execution Rules
+
+{SHARED_ENVIRONMENT}
+
+{SHARED_DUCKDB_NOTES}
+
+**Datetime handling:**
+- `date` columns contain date-only values (YYYY-MM-DD). `datetime` columns contain date+time (ISO 8601).
+- `time` columns contain time-only values (HH:mm:ss). `duration` columns are time intervals.
+- Year → number. Year-month / year-month-day → string ("2020-01" / "2020-01-01").
+- Hour alone → number. Hour:min or h:m:s → string. Never return raw datetime objects.
+
+### B. Chart Type Reference
+
+{SHARED_CHART_REFERENCE}
+
+### C. Semantic Type Reference
+
+{SHARED_SEMANTIC_TYPE_REFERENCE}
+
+### D. Statistical Analysis Guide
+
+{SHARED_STATISTICAL_ANALYSIS}
+"""
diff --git a/py-src/data_formulator/agents/client_utils.py b/py-src/data_formulator/agents/client_utils.py
index 637a4f75..0069c4b4 100644
--- a/py-src/data_formulator/agents/client_utils.py
+++ b/py-src/data_formulator/agents/client_utils.py
@@ -1,5 +1,4 @@
import litellm
-import openai
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
@@ -21,7 +20,10 @@ def __init__(self, endpoint, model, api_key=None, api_base=None, api_version=No
if api_version is not None and api_version != "":
self.params["api_version"] = api_version
- if self.endpoint == "gemini":
+ if self.endpoint == "openai":
+ if not model.startswith("openai/"):
+ self.model = f"openai/{model}"
+ elif self.endpoint == "gemini":
if model.startswith("gemini/"):
self.model = model
else:
@@ -85,6 +87,13 @@ def _is_image_deserialize_error(self, error_text: str) -> bool:
lowered = error_text.lower()
return ("image_url" in lowered and "expected `text`" in lowered) or "unknown variant `image_url`" in lowered
+ def _is_reasoning_effort_error(self, error_text: str) -> bool:
+ """Detect provider errors caused by an unsupported ``reasoning_effort``
+ value (e.g. ``"minimal"`` on a model that only accepts
+ ``none/low/medium/high/xhigh``). The provider message reliably
+ mentions the parameter name."""
+ return "reasoning_effort" in error_text.lower()
+
@classmethod
def from_config(cls, model_config: dict[str, str]):
"""
@@ -113,106 +122,72 @@ def ping(self, timeout: int = 10):
"""Lightweight connectivity check: send a minimal completion with
max_tokens=3 and a short timeout. Raises on any failure."""
messages = [{"role": "user", "content": "Reply only 'ok'."}]
+ params = self.params.copy()
+ params["timeout"] = timeout
+ litellm.completion(
+ model=self.model, messages=messages,
+ max_tokens=3, drop_params=True, **params,
+ )
- if self.endpoint == "openai":
- client = openai.OpenAI(
- base_url=self.params.get("api_base", None),
- api_key=self.params.get("api_key", ""),
- timeout=timeout,
- )
- client.chat.completions.create(
- model=self.model, messages=messages, max_tokens=3,
- )
- else:
- params = self.params.copy()
- params["timeout"] = timeout
- litellm.completion(
- model=self.model, messages=messages,
- max_tokens=3, drop_params=True, **params,
- )
+ def get_completion(self, messages, stream=False, reasoning_effort="low",
+ **kwargs):
+ """Send a chat completion request via LiteLLM.
- def get_completion(self, messages, stream=False):
+ All providers (OpenAI, Azure, Anthropic, etc.) are handled uniformly
+ by LiteLLM. ``drop_params=True`` ensures unsupported parameters
+ (like ``reasoning_effort`` on non-reasoning models) are silently
+ ignored rather than causing errors.
"""
- Returns a LiteLLM client configured for the specified endpoint and model.
- Supports OpenAI, Azure, Ollama, and other providers via LiteLLM.
- """
- # Configure LiteLLM
-
- if self.endpoint == "openai":
- client = openai.OpenAI(
- base_url=self.params.get("api_base", None),
- api_key=self.params.get("api_key", ""),
- timeout=120
+ params = self.params.copy()
+ params["reasoning_effort"] = reasoning_effort
+ params.update(kwargs)
+ try:
+ return litellm.completion(
+ model=self.model, messages=messages,
+ drop_params=True, stream=stream, **params,
)
-
- completion_params = {
- "model": self.model,
- "messages": messages,
- }
-
- if self.model.startswith("gpt-5") or self.model.startswith("o1") or self.model.startswith("o3"):
- completion_params["reasoning_effort"] = "low"
-
- try:
- return client.chat.completions.create(**completion_params, stream=stream)
- except Exception as e:
- error_text = str(e)
- if self._is_image_deserialize_error(error_text):
- sanitized_messages = self._strip_images_from_messages(messages)
- completion_params["messages"] = sanitized_messages
- return client.chat.completions.create(**completion_params, stream=stream)
- raise
- else:
-
- params = self.params.copy()
-
- if (self.model.startswith("gpt-5") or self.model.startswith("o1") or self.model.startswith("o3")
- or self.model.startswith("claude-sonnet-4-5") or self.model.startswith("claude-opus-4")):
- params["reasoning_effort"] = "low"
-
- try:
+ except Exception as e:
+ err = str(e)
+ if self._is_reasoning_effort_error(err):
+ params.pop("reasoning_effort", None)
return litellm.completion(
- model=self.model,
- messages=messages,
- drop_params=True,
- stream=stream,
- **params
+ model=self.model, messages=messages,
+ drop_params=True, stream=stream, **params,
)
- except Exception as e:
- error_text = str(e)
- if self._is_image_deserialize_error(error_text):
- sanitized_messages = self._strip_images_from_messages(messages)
- return litellm.completion(
- model=self.model,
- messages=sanitized_messages,
- drop_params=True,
- stream=stream,
- **params
- )
- raise
+ if self._is_image_deserialize_error(err):
+ sanitized = self._strip_images_from_messages(messages)
+ return litellm.completion(
+ model=self.model, messages=sanitized,
+ drop_params=True, stream=stream, **params,
+ )
+ raise
-
- def get_response(self, messages: list[dict], tools: list | None = None):
- """
- Returns a response using OpenAI's Response API approach.
+ def get_completion_with_tools(self, messages, tools, stream=False,
+ reasoning_effort="low", **kwargs):
+ """Send a chat completion request with tool definitions via LiteLLM.
+
+ Same as ``get_completion`` but accepts ``tools`` (and optional
+ ``tool_choice``, ``parallel_tool_calls``, etc. via ``**kwargs``).
"""
- if self.endpoint == "openai":
- client = openai.OpenAI(
- base_url=self.params.get("api_base", None),
- api_key=self.params.get("api_key", ""),
- timeout=120
+ params = self.params.copy()
+ params["reasoning_effort"] = reasoning_effort
+ try:
+ return litellm.completion(
+ model=self.model, messages=messages, tools=tools,
+ drop_params=True, stream=stream, **params, **kwargs,
)
- return client.responses.create(
- model=self.model,
- input=messages,
- tools=tools,
- **self.params
- )
- else:
- return litellm.responses(
- model=self.model,
- input=messages,
- tools=tools,
- drop_params=True,
- **self.params
- )
\ No newline at end of file
+ except Exception as e:
+ err = str(e)
+ if self._is_reasoning_effort_error(err):
+ params.pop("reasoning_effort", None)
+ return litellm.completion(
+ model=self.model, messages=messages, tools=tools,
+ drop_params=True, stream=stream, **params, **kwargs,
+ )
+ if self._is_image_deserialize_error(err):
+ sanitized = self._strip_images_from_messages(messages)
+ return litellm.completion(
+ model=self.model, messages=sanitized, tools=tools,
+ drop_params=True, stream=stream, **params, **kwargs,
+ )
+ raise
\ No newline at end of file
diff --git a/py-src/data_formulator/agents/context.py b/py-src/data_formulator/agents/context.py
index b110353c..c132a286 100644
--- a/py-src/data_formulator/agents/context.py
+++ b/py-src/data_formulator/agents/context.py
@@ -26,6 +26,61 @@
TABLE_SAMPLE_CHAR_LIMIT = 1000
+def _ensure_no_auth_catalogs_cached(user_home: Any) -> None:
+ """Populate the disk catalog cache for any admin connector that has no
+ required auth parameters and isn't cached yet.
+
+ Used to surface zero-config admin connectors (notably the built-in
+ ``sample_datasets`` connector) to the agent's search/read tools on
+ first use, without requiring an explicit "Connect" step in the UI.
+ Silent on failure — auth-gated connectors will simply remain
+ un-synced until the user provides credentials through the normal
+ flow.
+ """
+ if not user_home:
+ return
+ try:
+ from pathlib import Path
+ from data_formulator.data_connector import (
+ DATA_CONNECTORS,
+ _ADMIN_CONNECTOR_IDS,
+ )
+ from data_formulator.datalake.catalog_cache import save_catalog
+
+ cache_dir = Path(user_home) / "catalog_cache"
+ for source_id in list(_ADMIN_CONNECTOR_IDS):
+ cache_path = cache_dir / f"{source_id}.json"
+ if cache_path.exists():
+ continue
+ connector = DATA_CONNECTORS.get(source_id)
+ if not connector:
+ continue
+ loader_class = connector._loader_class
+ try:
+ params = loader_class.list_params()
+ except Exception:
+ continue
+ # Only auto-sync if no params are required (true no-auth case)
+ if any(p.get("required") for p in params):
+ continue
+ try:
+ loader = loader_class(connector._default_params or {})
+ if not loader.test_connection():
+ continue
+ tables = loader.sync_catalog_metadata()
+ save_catalog(Path(user_home), source_id, tables)
+ logger.info(
+ "Auto-synced catalog for '%s' (%d tables)",
+ source_id, len(tables),
+ )
+ except Exception:
+ logger.debug(
+ "Auto-sync failed for '%s'", source_id, exc_info=True,
+ )
+ except Exception:
+ logger.debug("Catalog auto-sync setup failed", exc_info=True)
+
+
def _get_workspace_metadata_lookups(workspace: Any) -> tuple[dict[str, str], dict[str, dict[str, str]], dict[str, str]]:
"""Return table descriptions, column descriptions, and import options from workspace metadata."""
table_descs: dict[str, str] = {}
@@ -284,91 +339,6 @@ def handle_inspect_source_data(
return content
-def handle_search_data_tables(
- query: str,
- scope: str,
- workspace: Any,
-) -> str:
- """Handle a search_data_tables tool call.
-
- Combines workspace metadata search (layer 1) and disk catalog cache
- search (layer 2) into a single Level 0 result set.
-
- The user home directory is resolved from ``workspace.user_home``
- automatically; catalog cache files live under ``/catalog_cache/``.
-
- Returns a text summary suitable for LLM consumption. Results are
- capped to keep context usage low (~3K tokens).
- """
- user_home = getattr(workspace, "user_home", None)
- if not query or not query.strip():
- return "Please provide a search keyword."
-
- results: list[dict[str, Any]] = []
-
- # ── Layer 1: workspace metadata search ───────────────────────────
- if scope in ("workspace", "all"):
- try:
- ws_meta = workspace.get_metadata()
- if ws_meta:
- ws_hits = ws_meta.search_tables(query, limit=50)
- for hit in ws_hits:
- results.append({
- "source": "workspace",
- "name": hit["name"],
- "description": (hit.get("description") or "")[:120],
- "matched_columns": hit.get("matched_columns", []),
- "column_count": hit.get("column_count", 0),
- "status": "imported",
- })
- except Exception:
- logger.debug("Workspace search failed", exc_info=True)
-
- # ── Layer 2: disk catalog cache search ───────────────────────────
- if scope in ("connected", "all") and user_home:
- try:
- from data_formulator.datalake.catalog_cache import search_catalog_cache
-
- imported_names = {r["name"] for r in results}
- cache_hits = search_catalog_cache(
- user_home,
- query,
- limit_per_source=20,
- exclude_tables=imported_names,
- )
- for hit in cache_hits:
- results.append({
- "source": hit.get("source_id", "connected"),
- "source_id": hit.get("source_id", ""),
- "table_key": hit.get("table_key", ""),
- "name": hit["name"],
- "description": (hit.get("description") or "")[:120],
- "matched_columns": hit.get("matched_columns", []),
- "column_count": hit.get("column_count", 0),
- "status": "not imported",
- })
- except Exception:
- logger.debug("Catalog cache search failed", exc_info=True)
-
- if not results:
- return f"No tables found matching '{query}'."
-
- lines = [f"Search results for '{query}' ({len(results)} matches):\n"]
- for i, r in enumerate(results, 1):
- line = f"{i}. [{r['source']}] {r['name']}"
- if r["description"]:
- line += f" — {r['description']}"
- if r["matched_columns"]:
- line += f" (matched columns: {', '.join(r['matched_columns'][:5])})"
- line += f" [{r['status']}]"
- if r.get("source_id") and r.get("table_key"):
- line += f" {{source_id: {r['source_id']}, table_key: {r['table_key']}}}"
- lines.append(line)
-
- text = "\n".join(lines)
- return text[:3000] + "\n..." if len(text) > 3000 else text
-
-
def handle_read_catalog_metadata(
source_id: str,
table_key: str,
@@ -389,6 +359,9 @@ def handle_read_catalog_metadata(
if not user_home:
return "Cannot read catalog metadata: user home not available."
+ # Surface zero-config admin connectors (e.g. sample_datasets) on first use.
+ _ensure_no_auth_catalogs_cached(user_home)
+
from pathlib import Path
from data_formulator.datalake.catalog_cache import load_catalog
diff --git a/py-src/data_formulator/agents/data_agent.py b/py-src/data_formulator/agents/data_agent.py
index 1b58bc15..8e9cd39a 100644
--- a/py-src/data_formulator/agents/data_agent.py
+++ b/py-src/data_formulator/agents/data_agent.py
@@ -7,9 +7,9 @@
- **Tools** (explore, inspect_source_data): Called via OpenAI tool-calling
API within a single LLM turn. The agent gathers data silently — these
are internal to the agent and not surfaced to the user.
- - **Actions** (visualize, clarify, explain, present): Structured JSON output
- in the LLM's text response. These are externalized to the user — each
- one ends the current turn and produces visible output.
+ - **Actions** (visualize, clarify, explain, summary, delegate): Structured
+ JSON output in the LLM's text response. These are externalized to the
+ user — each one ends the current turn and produces visible output.
The server-side while loop handles one action per iteration:
1. Call LLM (with tools) → agent may call tools internally
@@ -26,11 +26,11 @@
from pathlib import Path
from typing import Any, Generator
-import litellm
-import openai
import pandas as pd
+from data_formulator.agent_config import reasoning_effort_for
from data_formulator.agents.agent_utils import (
+ attach_reasoning_content,
ensure_output_variable_in_code,
extract_json_objects,
generate_data_summary,
@@ -40,11 +40,10 @@
build_lightweight_table_context,
build_peripheral_thread_context,
handle_inspect_source_data,
- handle_read_catalog_metadata,
- handle_search_data_tables,
)
from data_formulator.agents.client_utils import Client
-from data_formulator.prompts.chart_creation_guide import CHART_CREATION_GUIDE
+from data_formulator.datalake.parquet_utils import df_to_safe_records
+from data_formulator.agents.chart_creation_guide import CHART_CREATION_GUIDE
from data_formulator.security.code_signing import sign_result
from data_formulator.workflows.create_vl_plots import (
assemble_vegailte_chart,
@@ -56,8 +55,10 @@
logger = logging.getLogger(__name__)
+_AGENT_ID = "data_agent"
+
# ── Weak-model rescue helpers ─────────────────────────────────────────────
-# When a weaker LLM calls visualize/clarify/explain/present as a tool instead
+# When a weaker LLM calls visualize/clarify/explain/summary as a tool instead
# of outputting JSON in text, these helpers validate and normalise the args
# so the action can be rescued without wasting rounds.
@@ -65,9 +66,13 @@
"visualize": ["code", "output_variable", "chart"],
"clarify": ["questions"],
"explain": ["explanation"],
- "present": ["summary"],
+ "summary": ["summary"],
+ "delegate": ["target", "options"],
}
+# Valid targets for a `delegate` action.
+_DELEGATE_TARGETS: tuple[str, ...] = ("data_loading", "report_gen")
+
def _rescue_unpack_json_strings(data: dict) -> None:
"""In-place: parse values that are JSON-encoded strings back to objects.
@@ -96,27 +101,6 @@ def _rescue_validate_action(data: dict) -> list[str]:
# gather data before committing to a user-visible action.
TOOLS = [
- {
- "type": "function",
- "function": {
- "name": "think",
- "description": (
- "Share your reasoning or findings with the user before taking "
- "an action. Use this to explain what you discovered from the "
- "data and what you plan to do next."
- ),
- "parameters": {
- "type": "object",
- "properties": {
- "message": {
- "type": "string",
- "description": "Your reasoning, findings, or plan.",
- },
- },
- "required": ["message"],
- },
- },
- },
{
"type": "function",
"function": {
@@ -164,61 +148,6 @@ def _rescue_validate_action(data: dict) -> list[str]:
},
},
},
- {
- "type": "function",
- "function": {
- "name": "search_data_tables",
- "description": (
- "Search for tables by keyword across workspace and connected "
- "data sources. Returns Level 0 summaries: table name, one-line "
- "description, matched columns, and — for not-imported tables — "
- "source_id and table_key needed by read_catalog_metadata. "
- "Use inspect_source_data for imported tables, "
- "read_catalog_metadata for not-imported candidates."
- ),
- "parameters": {
- "type": "object",
- "properties": {
- "query": {
- "type": "string",
- "description": "Keyword to search for (matches table names, descriptions, column names, column descriptions).",
- },
- "scope": {
- "type": "string",
- "enum": ["workspace", "connected", "all"],
- "description": "Search scope: 'workspace' (imported tables only), 'connected' (cached catalogs from connected sources), 'all' (both).",
- },
- },
- "required": ["query"],
- },
- },
- },
- {
- "type": "function",
- "function": {
- "name": "read_catalog_metadata",
- "description": (
- "Read detailed metadata for a specific table from a connected "
- "data source's cached catalog. Shows columns, types, descriptions "
- "(both source and user-annotated), schema, row count, and metadata "
- "status. Use after search_data_tables finds a not-imported candidate."
- ),
- "parameters": {
- "type": "object",
- "properties": {
- "source_id": {
- "type": "string",
- "description": "The data source / connector ID (from search results).",
- },
- "table_key": {
- "type": "string",
- "description": "The table's unique key (UUID or _source_name, from search results).",
- },
- },
- "required": ["source_id", "table_key"],
- },
- },
- },
{
"type": "function",
"function": {
@@ -286,30 +215,23 @@ def _rescue_validate_action(data: dict) -> list[str]:
## Tools (internal — for data gathering)
-You have tools you can call to gather data and share reasoning:
+You have tools you can call to gather data:
-- **think(message)** — optionally share your reasoning or findings with
- the user before taking an action. Useful for complex analyses where
- you want to explain what you found and why you chose this chart.
- **explore(code)** — run Python code to inspect data, compute stats, etc.
**Important**: each call runs in a fresh namespace — variables do NOT
persist between calls. Combine all related operations (loading,
transforming, printing) into a single explore() call.
- **inspect_source_data(table_names)** — get schema, stats, and sample rows
for source tables (cheaper than explore for basic inspection).
-- **search_data_tables(query, scope)** — search for tables by keyword across
- workspace and connected data sources. Returns Level 0 summaries (name,
- description, matched columns). Not-imported results include ``source_id``
- and ``table_key`` — pass them to read_catalog_metadata to see full details.
- For imported tables, use inspect_source_data instead.
-- **read_catalog_metadata(source_id, table_key)** — read full cached metadata
- for a specific not-imported table from a connected source (columns, types,
- descriptions, schema, row count). Only use with ``source_id`` and
- ``table_key`` from search_data_tables results; do NOT fabricate these values.
- **search_knowledge(query, categories?)** — search the user's knowledge base
(rules, experiences) for relevant entries.
- **read_knowledge(category, path)** — read the full content of a knowledge entry.
+You analyse data that is **already in the workspace**. If the user's
+question requires data that isn't present, do NOT try to find it yourself —
+emit a `delegate` action targeting the Data Loading agent and the user
+can hand off in one click.
+
The initial context already includes sample rows and statistics for each
table. If the data is straightforward, proceed directly to your action
without calling tools. Tool results are returned to you before you
@@ -321,18 +243,18 @@ def _rescue_validate_action(data: dict) -> list[str]:
**exactly one action** as a JSON object in your text response. Actions
are shown to the user and end the current turn.
-⚠ **CRITICAL**: `visualize`, `clarify`, `explain`, and `present` are
-**actions**, NOT tools. Never call them via function/tool calling — they
-MUST appear as a JSON object in your **text reply**. Only the items
-listed in the Tools section above (`explore`, `inspect_source_data`,
-`search_data_tables`, `read_catalog_metadata`, `search_knowledge`,
-`read_knowledge`, `think`) may be invoked as tool calls.
+⚠ **CRITICAL**: `visualize`, `clarify`, `explain`, `summary`, and
+`delegate` are **actions**, NOT tools. Never call them via
+function/tool calling — they MUST appear as a JSON object in your **text
+reply**. Only the items listed in the Tools section above (`explore`,
+`inspect_source_data`, `search_knowledge`, `read_knowledge`) may be
+invoked as tool calls.
### `visualize`
```json
{{
"action": "visualize",
- "display_instruction": "",
+ "display_instruction": "<≤12 words. State the question or hypothesis the chart investigates — don't recap the chart spec (x/y/color/split are already visible). Bold a **column** if it anchors the question. ✗ 'Plotting price over time, split by fuel, to see trends'>",
"input_tables": ["