Skip to content

Commit

Permalink
add notebook with plots
Browse files Browse the repository at this point in the history
  • Loading branch information
nrlugg committed Nov 12, 2024
1 parent d8af621 commit b2e9d5c
Showing 1 changed file with 227 additions and 0 deletions.
227 changes: 227 additions & 0 deletions workspace.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RendererRegistry.enable('jupyterlab')"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import altair as alt\n",
"import duckdb\n",
"\n",
"alt.renderers.enable(\"jupyterlab\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"c = duckdb.connect(\"dbt.duckdb\", read_only=True)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.vegalite.v5+json": {
"$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
"continuousWidth": 300
}
},
"data": {
"name": "data-e9ffe44f4a940c91c142d6703ef79b9b"
},
"datasets": {
"data-e9ffe44f4a940c91c142d6703ef79b9b": [
{
"first_order_month": "2018-01-01T00:00:00",
"num_new_customers": 24
},
{
"first_order_month": "2018-02-01T00:00:00",
"num_new_customers": 18
},
{
"first_order_month": "2018-03-01T00:00:00",
"num_new_customers": 18
},
{
"first_order_month": "2018-04-01T00:00:00",
"num_new_customers": 2
}
]
},
"encoding": {
"x": {
"field": "first_order_month",
"timeUnit": "yearmonth",
"type": "temporal"
},
"y": {
"field": "num_new_customers",
"type": "quantitative"
}
},
"mark": {
"type": "bar"
}
},
"text/plain": [
"<VegaLite 5 object>\n",
"\n",
"If you see this message, it means the renderer has not been properly enabled\n",
"for the frontend that you are using. For more information, see\n",
"https://altair-viz.github.io/user_guide/display_frontends.html#troubleshooting\n"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t = c.sql(\n",
" \"\"\"\n",
" SELECT *\n",
" FROM fnl_sales_newcustomers\n",
" ORDER BY first_order_month\n",
" \"\"\"\n",
")\n",
"\n",
"(\n",
" alt.Chart(t)\n",
" .mark_bar()\n",
" .encode(\n",
" x=alt.X(\"yearmonth(first_order_month):T\"),\n",
" y=alt.Y(\"num_new_customers:Q\"),\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.vegalite.v5+json": {
"$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
"continuousWidth": 300
}
},
"data": {
"name": "data-f6fa15d27bf142925fe0f5eb72fd0105"
},
"datasets": {
"data-f6fa15d27bf142925fe0f5eb72fd0105": [
{
"customer_id": 1,
"total_returned_amount_aud": 10
},
{
"customer_id": 2,
"total_returned_amount_aud": 23
},
{
"customer_id": 40,
"total_returned_amount_aud": 3
},
{
"customer_id": 64,
"total_returned_amount_aud": 13
}
]
},
"encoding": {
"x": {
"field": "total_returned_amount_aud",
"type": "quantitative"
},
"y": {
"field": "customer_id",
"sort": "-x",
"type": "ordinal"
}
},
"mark": {
"type": "bar"
}
},
"text/plain": [
"<VegaLite 5 object>\n",
"\n",
"If you see this message, it means the renderer has not been properly enabled\n",
"for the frontend that you are using. For more information, see\n",
"https://altair-viz.github.io/user_guide/display_frontends.html#troubleshooting\n"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t = c.sql(\n",
" \"\"\"\n",
" SELECT *\n",
" FROM fnl_finance_returnsamout\n",
" WHERE total_returned_amount_aud > 0\n",
" \"\"\"\n",
")\n",
"\n",
"(\n",
" alt.Chart(t)\n",
" .mark_bar()\n",
" .encode(\n",
" x=alt.X(\"total_returned_amount_aud:Q\"),\n",
" y=alt.Y(\"customer_id:O\", sort=alt.Sort(\"-x\")),\n",
" )\n",
")"
]
}
],
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit b2e9d5c

Please sign in to comment.