Skip to content

Commit 30d3dbd

Browse files
committed
Add initial work on duckdb
1 parent 9f2627f commit 30d3dbd

File tree

4 files changed

+223
-0
lines changed

4 files changed

+223
-0
lines changed

source-code/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ to create it. There is some material not covered in the presentation as well.
2222
soup and graph representation using networkx.
2323
* [`xarray`](xarray): illustrates the xarray library for pandas-like operations
2424
on multi-dimensional arrays.
25+
* [`duckdb`](duckdb): illustrates the DuckDB library for SQL-like operations
26+
on dataframes, including integration with pandas and polars.
2527

2628
**Note:** material on dashboards has been moved to a [dedicated
2729
repository](https://github.com/gjbex/Python-dashboards).
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
,patient,dose,date,temperature
2+
0,1,0.0,2012-10-02 10:00:00,38.3
3+
1,1,2.0,2012-10-02 11:00:00,38.5
4+
2,1,2.0,2012-10-02 12:00:00,38.1
5+
3,1,2.0,2012-10-02 13:00:00,37.3
6+
4,1,0.0,2012-10-02 14:00:00,37.5
7+
5,1,0.0,2012-10-02 15:00:00,37.1
8+
6,1,0.0,2012-10-02 16:00:00,36.8
9+
7,2,0.0,2012-10-02 10:00:00,39.3
10+
8,2,5.0,2012-10-02 11:00:00,39.4
11+
9,2,5.0,2012-10-02 12:00:00,38.1
12+
10,2,5.0,2012-10-02 13:00:00,37.3
13+
11,2,0.0,2012-10-02 14:00:00,36.8
14+
12,2,0.0,2012-10-02 15:00:00,36.8
15+
13,2,0.0,2012-10-02 16:00:00,36.8
16+
14,3,0.0,2012-10-02 10:00:00,37.9
17+
15,3,2.0,2012-10-02 11:00:00,39.5
18+
16,3,5.0,2012-10-02 12:00:00,38.3
19+
17,3,2.0,2012-10-02 13:00:00,
20+
18,3,2.0,2012-10-02 14:00:00,37.7
21+
19,3,2.0,2012-10-02 15:00:00,37.1
22+
20,3,0.0,2012-10-02 16:00:00,36.7
23+
21,4,0.0,2012-10-02 10:00:00,38.1
24+
22,4,5.0,2012-10-02 11:00:00,37.2
25+
23,4,5.0,2012-10-02 12:00:00,36.1
26+
24,4,0.0,2012-10-02 13:00:00,35.9
27+
25,4,,2012-10-02 14:00:00,36.3
28+
26,4,0.0,2012-10-02 15:00:00,36.6
29+
27,4,0.0,2012-10-02 16:00:00,36.7
30+
28,5,0.0,2012-10-02 10:00:00,37.9
31+
29,5,3.0,2012-10-02 11:00:00,39.5
32+
30,5,7.0,2012-10-02 12:00:00,38.3
33+
31,5,5.0,2012-10-02 13:00:00,38.5
34+
32,5,9.0,2012-10-02 14:00:00,39.4
35+
33,5,3.0,2012-10-02 15:00:00,37.9
36+
34,5,0.0,2012-10-02 16:00:00,37.2
37+
35,6,0.0,2012-10-02 10:00:00,37.5
38+
36,6,2.0,2012-10-02 11:00:00,38.1
39+
37,6,3.0,2012-10-02 12:00:00,37.9
40+
38,6,2.0,2012-10-02 13:00:00,37.7
41+
39,6,1.0,2012-10-02 14:00:00,37.2
42+
40,6,0.0,2012-10-02 15:00:00,36.8
43+
41,7,0.0,2012-10-02 10:00:00,39.5
44+
42,7,10.0,2012-10-02 11:00:00,40.7
45+
43,7,5.0,2012-10-02 12:00:00,39.8
46+
44,7,8.0,2012-10-02 13:00:00,40.2
47+
45,7,3.0,2012-10-02 14:00:00,38.3
48+
46,7,3.0,2012-10-02 15:00:00,37.6
49+
47,7,1.0,2012-10-02 16:00:00,37.3
50+
48,8,0.0,2012-10-02 10:00:00,37.8
51+
49,8,0.0,2012-10-02 11:00:00,37.9
52+
50,8,0.0,2012-10-02 12:00:00,37.4
53+
51,8,0.0,2012-10-02 13:00:00,37.6
54+
52,8,0.0,2012-10-02 14:00:00,37.3
55+
53,8,0.0,2012-10-02 15:00:00,37.1
56+
54,8,0.0,2012-10-02 16:00:00,36.8
57+
55,9,0.0,2012-10-02 10:00:00,38.3
58+
56,9,10.0,2012-10-02 11:00:00,39.5
59+
57,9,12.0,2012-10-02 12:00:00,40.2
60+
58,9,4.0,2012-10-02 13:00:00,39.1
61+
59,9,4.0,2012-10-02 14:00:00,37.9
62+
60,9,0.0,2012-10-02 15:00:00,37.1
63+
61,9,0.0,2012-10-02 16:00:00,37.3
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
,patient,gender,condition
2+
0,1,M,A
3+
1,2,F,A
4+
2,3,M,A
5+
3,5,M,A
6+
4,6,F,B
7+
5,7,M,B
8+
6,8,F,B
9+
7,9,M,B
10+
8,10,F,B
11+
9,11,M,B

source-code/duckdb/patients.ipynb

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "4c0d0975-71ce-4e9a-986c-ac6cbfb251bb",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import duckdb\n",
11+
"import pandas as pd"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 33,
17+
"id": "861daf66-0810-48d9-968c-18e1dabe0e4f",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"conn = duckdb.connect('data/patient_experiment.csv')"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 37,
27+
"id": "c0f56de5-2351-4473-b768-234a89a705ac",
28+
"metadata": {},
29+
"outputs": [
30+
{
31+
"data": {
32+
"text/html": [
33+
"<div>\n",
34+
"<style scoped>\n",
35+
" .dataframe tbody tr th:only-of-type {\n",
36+
" vertical-align: middle;\n",
37+
" }\n",
38+
"\n",
39+
" .dataframe tbody tr th {\n",
40+
" vertical-align: top;\n",
41+
" }\n",
42+
"\n",
43+
" .dataframe thead th {\n",
44+
" text-align: right;\n",
45+
" }\n",
46+
"</style>\n",
47+
"<table border=\"1\" class=\"dataframe\">\n",
48+
" <thead>\n",
49+
" <tr style=\"text-align: right;\">\n",
50+
" <th></th>\n",
51+
" <th>patient</th>\n",
52+
" </tr>\n",
53+
" </thead>\n",
54+
" <tbody>\n",
55+
" <tr>\n",
56+
" <th>0</th>\n",
57+
" <td>5</td>\n",
58+
" </tr>\n",
59+
" <tr>\n",
60+
" <th>1</th>\n",
61+
" <td>9</td>\n",
62+
" </tr>\n",
63+
" <tr>\n",
64+
" <th>2</th>\n",
65+
" <td>2</td>\n",
66+
" </tr>\n",
67+
" <tr>\n",
68+
" <th>3</th>\n",
69+
" <td>8</td>\n",
70+
" </tr>\n",
71+
" <tr>\n",
72+
" <th>4</th>\n",
73+
" <td>3</td>\n",
74+
" </tr>\n",
75+
" <tr>\n",
76+
" <th>5</th>\n",
77+
" <td>6</td>\n",
78+
" </tr>\n",
79+
" <tr>\n",
80+
" <th>6</th>\n",
81+
" <td>4</td>\n",
82+
" </tr>\n",
83+
" <tr>\n",
84+
" <th>7</th>\n",
85+
" <td>7</td>\n",
86+
" </tr>\n",
87+
" <tr>\n",
88+
" <th>8</th>\n",
89+
" <td>1</td>\n",
90+
" </tr>\n",
91+
" </tbody>\n",
92+
"</table>\n",
93+
"</div>"
94+
],
95+
"text/plain": [
96+
" patient\n",
97+
"0 5\n",
98+
"1 9\n",
99+
"2 2\n",
100+
"3 8\n",
101+
"4 3\n",
102+
"5 6\n",
103+
"6 4\n",
104+
"7 7\n",
105+
"8 1"
106+
]
107+
},
108+
"execution_count": 37,
109+
"metadata": {},
110+
"output_type": "execute_result"
111+
}
112+
],
113+
"source": [
114+
"conn.execute('SELECT DISTINCT patient FROM \"data/patient_experiment.csv\";').df()"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"id": "0c4e1ad8-a9ae-4808-901b-c036e4e0ee17",
121+
"metadata": {},
122+
"outputs": [],
123+
"source": []
124+
}
125+
],
126+
"metadata": {
127+
"kernelspec": {
128+
"display_name": "Python 3 (ipykernel)",
129+
"language": "python",
130+
"name": "python3"
131+
},
132+
"language_info": {
133+
"codemirror_mode": {
134+
"name": "ipython",
135+
"version": 3
136+
},
137+
"file_extension": ".py",
138+
"mimetype": "text/x-python",
139+
"name": "python",
140+
"nbconvert_exporter": "python",
141+
"pygments_lexer": "ipython3",
142+
"version": "3.12.11"
143+
}
144+
},
145+
"nbformat": 4,
146+
"nbformat_minor": 5
147+
}

0 commit comments

Comments
 (0)