Skip to content

Commit ba8d1d3

Browse files
authored
Merge pull request #86 from paddymul/master
Add Jupyterlite
2 parents 7c4b573 + 304da8f commit ba8d1d3

21 files changed

+237
-311
lines changed

.github/workflows/deploy.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- '*'
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.12'
23+
24+
- name: Install mamba
25+
uses: mamba-org/setup-micromamba@v1
26+
with:
27+
micromamba-version: '1.5.8-0'
28+
environment-file: build-environment.yml
29+
cache-environment: true
30+
31+
- name: Build the JupyterLite site
32+
shell: bash -l {0}
33+
run: |
34+
cp README.md content
35+
jupyter lite build --contents cookbook --output-dir dist
36+
37+
- name: Upload artifact
38+
uses: actions/upload-pages-artifact@v3
39+
with:
40+
path: ./dist
41+
42+
deploy:
43+
needs: build
44+
if: github.ref == 'refs/heads/master'
45+
permissions:
46+
pages: write
47+
id-token: write
48+
49+
environment:
50+
name: github-pages
51+
url: ${{ steps.deployment.outputs.page_url }}
52+
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Deploy to GitHub Pages
56+
id: deployment
57+
uses: actions/deploy-pages@v4

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
Pandas cookbook
22
===============
33

4-
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/jvns/pandas-cookbook/master)
4+
5+
Try it with Jupyter Lite
6+
[![lite-badge](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://paddymul.github.io/pandas-cookbook/lab/index.html)
7+
58

69
[pandas](http://pandas.pydata.org/) is a Python library for doing
710
data analysis. It's really fast and lets you do exploratory work
@@ -78,6 +81,13 @@ A tab should open up in your browser at `http://localhost:8888`
7881

7982
Happy pandas!
8083

84+
Running Jupyterlite locally
85+
===========================
86+
```bash
87+
#assuming you checked out into ~/code/pandas-cookbook
88+
cd ~/code/pandas-cookbook/ ; rm -rf _output ; time jupyter lite build --contents ./cookbook/ && cd _output && python -m http.server
89+
```
90+
8191
Running the cookbook inside a Docker container.
8292
===============================================================
8393
This repository contains a Dockerfile and can be built into a docker container.

build-environment.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: build-env
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python
6+
- pip
7+
- jupyter_server
8+
- jupyterlite-core >=0.4.1,<0.5.0
9+
- jupyterlite-xeus>=2.0.0,<3

cookbook/Chapter 1 - Reading from a CSV.ipynb

+27-269
Large diffs are not rendered by default.

cookbook/Chapter 2 - Selecting data & finding the most common complaint type.ipynb

+11-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"outputs": [],
3737
"source": [
3838
"# because of mixed types we specify dtype to prevent any errors\n",
39-
"complaints = pd.read_csv('../data/311-service-requests.csv', dtype='unicode')"
39+
"complaints = pd.read_csv('./data/311-service-requests.csv', dtype='unicode')"
4040
]
4141
},
4242
{
@@ -1693,7 +1693,7 @@
16931693
],
16941694
"metadata": {
16951695
"kernelspec": {
1696-
"display_name": "Python 3",
1696+
"display_name": "Python 3 (ipykernel)",
16971697
"language": "python",
16981698
"name": "python3"
16991699
},
@@ -1707,9 +1707,16 @@
17071707
"name": "python",
17081708
"nbconvert_exporter": "python",
17091709
"pygments_lexer": "ipython3",
1710-
"version": "3.8.5"
1710+
"version": "3.9.20"
1711+
},
1712+
"widgets": {
1713+
"application/vnd.jupyter.widget-state+json": {
1714+
"state": {},
1715+
"version_major": 2,
1716+
"version_minor": 0
1717+
}
17111718
}
17121719
},
17131720
"nbformat": 4,
1714-
"nbformat_minor": 1
1721+
"nbformat_minor": 4
17151722
}

cookbook/Chapter 3 - Which borough has the most noise complaints (or, more selecting data).ipynb

+11-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"outputs": [],
3737
"source": [
3838
"# because of mixed types we specify dtype to prevent any errors\n",
39-
"complaints = pd.read_csv('../data/311-service-requests.csv', dtype='unicode')"
39+
"complaints = pd.read_csv('./data/311-service-requests.csv', dtype='unicode')"
4040
]
4141
},
4242
{
@@ -1607,7 +1607,7 @@
16071607
],
16081608
"metadata": {
16091609
"kernelspec": {
1610-
"display_name": "Python 3",
1610+
"display_name": "Python 3 (ipykernel)",
16111611
"language": "python",
16121612
"name": "python3"
16131613
},
@@ -1621,9 +1621,16 @@
16211621
"name": "python",
16221622
"nbconvert_exporter": "python",
16231623
"pygments_lexer": "ipython3",
1624-
"version": "3.8.5"
1624+
"version": "3.9.20"
1625+
},
1626+
"widgets": {
1627+
"application/vnd.jupyter.widget-state+json": {
1628+
"state": {},
1629+
"version_major": 2,
1630+
"version_minor": 0
1631+
}
16251632
}
16261633
},
16271634
"nbformat": 4,
1628-
"nbformat_minor": 1
1635+
"nbformat_minor": 4
16291636
}

cookbook/Chapter 4 - Find out on which weekday people bike the most with groupby and aggregate.ipynb

+12-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
}
7171
],
7272
"source": [
73-
"bikes = pd.read_csv('../data/bikes.csv', sep=';', encoding='latin1', parse_dates=['Date'], dayfirst=True, index_col='Date')\n",
73+
"bikes = pd.read_csv('./data/bikes.csv', sep=';', encoding='latin1', parse_dates=['Date'], dayfirst=True, index_col='Date')\n",
7474
"bikes['Berri 1'].plot()"
7575
]
7676
},
@@ -628,7 +628,7 @@
628628
}
629629
],
630630
"source": [
631-
"bikes = pd.read_csv('../data/bikes.csv', \n",
631+
"bikes = pd.read_csv('./data/bikes.csv', \n",
632632
" sep=';', encoding='latin1', \n",
633633
" parse_dates=['Date'], dayfirst=True, \n",
634634
" index_col='Date')\n",
@@ -652,7 +652,7 @@
652652
],
653653
"metadata": {
654654
"kernelspec": {
655-
"display_name": "Python 3",
655+
"display_name": "Python 3 (ipykernel)",
656656
"language": "python",
657657
"name": "python3"
658658
},
@@ -666,9 +666,16 @@
666666
"name": "python",
667667
"nbconvert_exporter": "python",
668668
"pygments_lexer": "ipython3",
669-
"version": "3.8.5"
669+
"version": "3.9.20"
670+
},
671+
"widgets": {
672+
"application/vnd.jupyter.widget-state+json": {
673+
"state": {},
674+
"version_major": 2,
675+
"version_minor": 0
676+
}
670677
}
671678
},
672679
"nbformat": 4,
673-
"nbformat_minor": 1
680+
"nbformat_minor": 4
674681
}

cookbook/Chapter 5 - Combining dataframes and scraping Canadian weather data.ipynb

+23-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 2,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -63,7 +63,7 @@
6363
}
6464
],
6565
"source": [
66-
"weather_2012_final = pd.read_csv('../data/weather_2012.csv', index_col='Date/Time')\n",
66+
"weather_2012_final = pd.read_csv('./data/weather_2012.csv', index_col='Date/Time')\n",
6767
"weather_2012_final['Temp (C)'].plot(figsize=(15, 6))"
6868
]
6969
},
@@ -85,6 +85,15 @@
8585
"Here's an URL template you can use to get data in Montreal. "
8686
]
8787
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"#downloading via URLS doesn't work in Jupyterlite"
95+
]
96+
},
8897
{
8998
"cell_type": "code",
9099
"execution_count": 15,
@@ -103,15 +112,15 @@
103112
},
104113
{
105114
"cell_type": "code",
106-
"execution_count": 17,
115+
"execution_count": 3,
107116
"metadata": {},
108117
"outputs": [],
109118
"source": [
110119
"#url = url_template.format(month=3, year=2012)\n",
111120
"#weather_mar2012 = pd.read_csv(url, skiprows=15, index_col='Date/Time', parse_dates=True, encoding='latin1', header=True)\n",
112121
"\n",
113122
"# because the url is broken, we use our saved dataframe for now\n",
114-
"weather_mar2012 = pd.read_csv('../data/weather_2012.csv')"
123+
"weather_mar2012 = pd.read_csv('./data/weather_2012.csv')"
115124
]
116125
},
117126
{
@@ -1905,7 +1914,7 @@
19051914
],
19061915
"metadata": {
19071916
"kernelspec": {
1908-
"display_name": "Python 3",
1917+
"display_name": "Python 3 (ipykernel)",
19091918
"language": "python",
19101919
"name": "python3"
19111920
},
@@ -1919,9 +1928,16 @@
19191928
"name": "python",
19201929
"nbconvert_exporter": "python",
19211930
"pygments_lexer": "ipython3",
1922-
"version": "3.8.5"
1931+
"version": "3.9.20"
1932+
},
1933+
"widgets": {
1934+
"application/vnd.jupyter.widget-state+json": {
1935+
"state": {},
1936+
"version_major": 2,
1937+
"version_minor": 0
1938+
}
19231939
}
19241940
},
19251941
"nbformat": 4,
1926-
"nbformat_minor": 1
1942+
"nbformat_minor": 4
19271943
}

cookbook/Chapter 6 - String Operations- Which month was the snowiest.ipynb

+11-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
}
157157
],
158158
"source": [
159-
"weather_2012 = pd.read_csv('../data/weather_2012.csv', parse_dates=True, index_col='Date/Time')\n",
159+
"weather_2012 = pd.read_csv('./data/weather_2012.csv', parse_dates=True, index_col='Date/Time')\n",
160160
"weather_2012[:5]"
161161
]
162162
},
@@ -717,7 +717,7 @@
717717
],
718718
"metadata": {
719719
"kernelspec": {
720-
"display_name": "Python 3",
720+
"display_name": "Python 3 (ipykernel)",
721721
"language": "python",
722722
"name": "python3"
723723
},
@@ -731,9 +731,16 @@
731731
"name": "python",
732732
"nbconvert_exporter": "python",
733733
"pygments_lexer": "ipython3",
734-
"version": "3.8.5"
734+
"version": "3.9.20"
735+
},
736+
"widgets": {
737+
"application/vnd.jupyter.widget-state+json": {
738+
"state": {},
739+
"version_major": 2,
740+
"version_minor": 0
741+
}
735742
}
736743
},
737744
"nbformat": 4,
738-
"nbformat_minor": 1
745+
"nbformat_minor": 4
739746
}

cookbook/Chapter 7 - Cleaning up messy data.ipynb

+13-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"metadata": {},
4040
"outputs": [],
4141
"source": [
42-
"requests = pd.read_csv('../data/311-service-requests.csv', dtype='unicode')"
42+
"requests = pd.read_csv('./data/311-service-requests.csv', dtype='unicode')"
4343
]
4444
},
4545
{
@@ -149,7 +149,7 @@
149149
"outputs": [],
150150
"source": [
151151
"na_values = ['NO CLUE', 'N/A', '0']\n",
152-
"requests = pd.read_csv('../data/311-service-requests.csv', na_values=na_values, dtype={'Incident Zip': str})"
152+
"requests = pd.read_csv('./data/311-service-requests.csv', na_values=na_values, dtype={'Incident Zip': str})"
153153
]
154154
},
155155
{
@@ -1194,7 +1194,7 @@
11941194
"outputs": [],
11951195
"source": [
11961196
"na_values = ['NO CLUE', 'N/A', '0']\n",
1197-
"requests = pd.read_csv('../data/311-service-requests.csv', \n",
1197+
"requests = pd.read_csv('./data/311-service-requests.csv', \n",
11981198
" na_values=na_values, \n",
11991199
" dtype={'Incident Zip': str})"
12001200
]
@@ -1337,7 +1337,7 @@
13371337
],
13381338
"metadata": {
13391339
"kernelspec": {
1340-
"display_name": "Python 3",
1340+
"display_name": "Python 3 (ipykernel)",
13411341
"language": "python",
13421342
"name": "python3"
13431343
},
@@ -1351,9 +1351,16 @@
13511351
"name": "python",
13521352
"nbconvert_exporter": "python",
13531353
"pygments_lexer": "ipython3",
1354-
"version": "3.8.5"
1354+
"version": "3.9.20"
1355+
},
1356+
"widgets": {
1357+
"application/vnd.jupyter.widget-state+json": {
1358+
"state": {},
1359+
"version_major": 2,
1360+
"version_minor": 0
1361+
}
13551362
}
13561363
},
13571364
"nbformat": 4,
1358-
"nbformat_minor": 1
1365+
"nbformat_minor": 4
13591366
}

0 commit comments

Comments
 (0)