Skip to content

Instantly share code, notes, and snippets.

@lostmygithubaccount
Created August 25, 2023 15:47
Show Gist options
  • Save lostmygithubaccount/73414943a71ffb471605c3132eda0727 to your computer and use it in GitHub Desktop.
Save lostmygithubaccount/73414943a71ffb471605c3132eda0727 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2af6d201",
"metadata": {},
"outputs": [],
"source": [
"import ibis"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8d8fde52",
"metadata": {},
"outputs": [],
"source": [
"ibis.set_backend(\"datafusion\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4e387c42",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">DatabaseTable: _ibis_read_delta_foodgjqjqncmbiedbjcu6qb7se\n",
" species string\n",
" island string\n",
" bill_length_mm float64\n",
" bill_depth_mm float64\n",
" flipper_length_mm int64\n",
" body_mass_g int64\n",
" sex string\n",
" year int64\n",
"</pre>\n"
],
"text/plain": [
"DatabaseTable: _ibis_read_delta_foodgjqjqncmbiedbjcu6qb7se\n",
" species string\n",
" island string\n",
" bill_length_mm float64\n",
" bill_depth_mm float64\n",
" flipper_length_mm int64\n",
" body_mass_g int64\n",
" sex string\n",
" year int64"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t = ibis.read_delta(\"penguins.delta\")\n",
"t"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "dca406fc",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━┓\n",
"┃<span style=\"font-weight: bold\"> species </span>┃<span style=\"font-weight: bold\"> island </span>┃<span style=\"font-weight: bold\"> bill_length_mm </span>┃<span style=\"font-weight: bold\"> bill_depth_mm </span>┃<span style=\"font-weight: bold\"> flipper_length_mm </span>┃<span style=\"font-weight: bold\"> body_mass_g </span>┃<span style=\"font-weight: bold\"> sex </span>┃<span style=\"font-weight: bold\"> year </span>┃\n",
"┡━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━┩\n",
"│ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">float64</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">float64</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">int64</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">int64</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">int64</span> │\n",
"├─────────┼───────────┼────────────────┼───────────────┼───────────────────┼─────────────┼────────┼───────┤\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">39.1</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">18.7</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">181</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3750</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">male </span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">39.5</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17.4</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">186</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3800</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">female</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">40.3</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">18.0</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">195</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3250</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">female</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">nan</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">nan</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">36.7</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">19.3</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">193</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3450</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">female</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">39.3</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">20.6</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">190</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3650</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">male </span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">38.9</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17.8</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">181</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3625</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">female</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">39.2</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">19.6</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">195</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4675</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">male </span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">34.1</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">18.1</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">193</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3475</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">42.0</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">20.2</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">190</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4250</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2007</span> │\n",
"│ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">…</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">…</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">…</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">…</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">…</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">…</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">…</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">…</span> │\n",
"└─────────┴───────────┴────────────────┴───────────────┴───────────────────┴─────────────┴────────┴───────┘\n",
"</pre>\n"
],
"text/plain": [
"┏━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━┓\n",
"┃\u001b[1m \u001b[0m\u001b[1mspecies\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1misland\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mbill_length_mm\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mbill_depth_mm\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mflipper_length_mm\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mbody_mass_g\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1msex\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1myear\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\n",
"┡━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━┩\n",
"│ \u001b[2mstring\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2mfloat64\u001b[0m │ \u001b[2mfloat64\u001b[0m │ \u001b[2mint64\u001b[0m │ \u001b[2mint64\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2mint64\u001b[0m │\n",
"├─────────┼───────────┼────────────────┼───────────────┼───────────────────┼─────────────┼────────┼───────┤\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m39.1\u001b[0m │ \u001b[1;36m18.7\u001b[0m │ \u001b[1;36m181\u001b[0m │ \u001b[1;36m3750\u001b[0m │ \u001b[32mmale \u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m39.5\u001b[0m │ \u001b[1;36m17.4\u001b[0m │ \u001b[1;36m186\u001b[0m │ \u001b[1;36m3800\u001b[0m │ \u001b[32mfemale\u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m40.3\u001b[0m │ \u001b[1;36m18.0\u001b[0m │ \u001b[1;36m195\u001b[0m │ \u001b[1;36m3250\u001b[0m │ \u001b[32mfemale\u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36mnan\u001b[0m │ \u001b[1;36mnan\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m36.7\u001b[0m │ \u001b[1;36m19.3\u001b[0m │ \u001b[1;36m193\u001b[0m │ \u001b[1;36m3450\u001b[0m │ \u001b[32mfemale\u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m39.3\u001b[0m │ \u001b[1;36m20.6\u001b[0m │ \u001b[1;36m190\u001b[0m │ \u001b[1;36m3650\u001b[0m │ \u001b[32mmale \u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m38.9\u001b[0m │ \u001b[1;36m17.8\u001b[0m │ \u001b[1;36m181\u001b[0m │ \u001b[1;36m3625\u001b[0m │ \u001b[32mfemale\u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m39.2\u001b[0m │ \u001b[1;36m19.6\u001b[0m │ \u001b[1;36m195\u001b[0m │ \u001b[1;36m4675\u001b[0m │ \u001b[32mmale \u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m34.1\u001b[0m │ \u001b[1;36m18.1\u001b[0m │ \u001b[1;36m193\u001b[0m │ \u001b[1;36m3475\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m42.0\u001b[0m │ \u001b[1;36m20.2\u001b[0m │ \u001b[1;36m190\u001b[0m │ \u001b[1;36m4250\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[1;36m2007\u001b[0m │\n",
"│ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │\n",
"└─────────┴───────────┴────────────────┴───────────────┴───────────────────┴─────────────┴────────┴───────┘"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ibis.options.interactive = True\n",
"t"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2388d27d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┓\n",
"┃<span style=\"font-weight: bold\"> species </span>┃<span style=\"font-weight: bold\"> island </span>┃<span style=\"font-weight: bold\"> count </span>┃\n",
"┡━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━┩\n",
"│ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">int64</span> │\n",
"├───────────┼───────────┼───────┤\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Gentoo </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Biscoe </span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">124</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Chinstrap</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Dream </span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">68</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Dream </span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">56</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Torgersen</span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">52</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">Adelie </span> │ <span style=\"color: #008000; text-decoration-color: #008000\">Biscoe </span> │ <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">44</span> │\n",
"└───────────┴───────────┴───────┘\n",
"</pre>\n"
],
"text/plain": [
"┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┓\n",
"┃\u001b[1m \u001b[0m\u001b[1mspecies\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1misland\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mcount\u001b[0m\u001b[1m \u001b[0m┃\n",
"┡━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━┩\n",
"│ \u001b[2mstring\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2mint64\u001b[0m │\n",
"├───────────┼───────────┼───────┤\n",
"│ \u001b[32mGentoo \u001b[0m │ \u001b[32mBiscoe \u001b[0m │ \u001b[1;36m124\u001b[0m │\n",
"│ \u001b[32mChinstrap\u001b[0m │ \u001b[32mDream \u001b[0m │ \u001b[1;36m68\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mDream \u001b[0m │ \u001b[1;36m56\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mTorgersen\u001b[0m │ \u001b[1;36m52\u001b[0m │\n",
"│ \u001b[32mAdelie \u001b[0m │ \u001b[32mBiscoe \u001b[0m │ \u001b[1;36m44\u001b[0m │\n",
"└───────────┴───────────┴───────┘"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grouped = t.group_by([\"species\", \"island\"]).agg(count=ibis._.count()).order_by(ibis._[\"count\"].desc())\n",
"grouped"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a3275d71",
"metadata": {},
"outputs": [],
"source": [
"import altair as alt"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "d45a903d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" #altair-viz-a5059448d1dc4f358aef3df9f87619d6.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-a5059448d1dc4f358aef3df9f87619d6.vega-embed details,\n",
" #altair-viz-a5059448d1dc4f358aef3df9f87619d6.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-a5059448d1dc4f358aef3df9f87619d6\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-a5059448d1dc4f358aef3df9f87619d6\") {\n",
" outputDiv = document.getElementById(\"altair-viz-a5059448d1dc4f358aef3df9f87619d6\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
" \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
" \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.14.1?noext\",\n",
" \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
" };\n",
"\n",
" function maybeLoadScript(lib, version) {\n",
" var key = `${lib.replace(\"-\", \"\")}_version`;\n",
" return (VEGA_DEBUG[key] == version) ?\n",
" Promise.resolve(paths[lib]) :\n",
" new Promise(function(resolve, reject) {\n",
" var s = document.createElement('script');\n",
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
" s.async = true;\n",
" s.onload = () => {\n",
" VEGA_DEBUG[key] = version;\n",
" return resolve(paths[lib]);\n",
" };\n",
" s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
" s.src = paths[lib];\n",
" });\n",
" }\n",
"\n",
" function showError(err) {\n",
" outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
" throw err;\n",
" }\n",
"\n",
" function displayChart(vegaEmbed) {\n",
" vegaEmbed(outputDiv, spec, embedOpt)\n",
" .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
" }\n",
"\n",
" if(typeof define === \"function\" && define.amd) {\n",
" requirejs.config({paths});\n",
" require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
" } else {\n",
" maybeLoadScript(\"vega\", \"5\")\n",
" .then(() => maybeLoadScript(\"vega-lite\", \"5.14.1\"))\n",
" .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
" .catch(showError)\n",
" .then(() => displayChart(vegaEmbed));\n",
" }\n",
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-8f43fa7ad8959351f525ec1276fbb5b5\"}, \"mark\": {\"type\": \"bar\"}, \"encoding\": {\"x\": {\"field\": \"species\", \"type\": \"nominal\"}, \"y\": {\"field\": \"count\", \"type\": \"quantitative\"}}, \"height\": 400, \"width\": 600, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.14.1.json\", \"datasets\": {\"data-8f43fa7ad8959351f525ec1276fbb5b5\": [{\"species\": \"Gentoo\", \"island\": \"Biscoe\", \"count\": 124}, {\"species\": \"Chinstrap\", \"island\": \"Dream\", \"count\": 68}, {\"species\": \"Adelie\", \"island\": \"Dream\", \"count\": 56}, {\"species\": \"Adelie\", \"island\": \"Torgersen\", \"count\": 52}, {\"species\": \"Adelie\", \"island\": \"Biscoe\", \"count\": 44}]}}, {\"mode\": \"vega-lite\"});\n",
"</script>"
],
"text/plain": [
"alt.Chart(...)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chart = (\n",
" alt.Chart(grouped)\n",
" .mark_bar()\n",
" .encode(\n",
" x=\"species\",\n",
" y=\"count\",\n",
" )\n",
" .properties(width=600, height=400)\n",
")\n",
"chart"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
@lostmygithubaccount
Copy link
Author

chart doesn't render here for some reason but does work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment