Skip to content

Commit

Permalink
Merge pull request #86 from paddymul/master
Browse files Browse the repository at this point in the history
Add Jupyterlite
  • Loading branch information
jvns authored Oct 22, 2024
2 parents 7c4b573 + 304da8f commit ba8d1d3
Show file tree
Hide file tree
Showing 21 changed files with 237 additions and 311 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build and Deploy

on:
push:
branches:
- main
- master
pull_request:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install mamba
uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: '1.5.8-0'
environment-file: build-environment.yml
cache-environment: true

- name: Build the JupyterLite site
shell: bash -l {0}
run: |
cp README.md content
jupyter lite build --contents cookbook --output-dir dist
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./dist

deploy:
needs: build
if: github.ref == 'refs/heads/master'
permissions:
pages: write
id-token: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Pandas cookbook
===============

[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/jvns/pandas-cookbook/master)

Try it with Jupyter Lite
[![lite-badge](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://paddymul.github.io/pandas-cookbook/lab/index.html)


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

Happy pandas!

Running Jupyterlite locally
===========================
```bash
#assuming you checked out into ~/code/pandas-cookbook
cd ~/code/pandas-cookbook/ ; rm -rf _output ; time jupyter lite build --contents ./cookbook/ && cd _output && python -m http.server
```

Running the cookbook inside a Docker container.
===============================================================
This repository contains a Dockerfile and can be built into a docker container.
Expand Down
9 changes: 9 additions & 0 deletions build-environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: build-env
channels:
- conda-forge
dependencies:
- python
- pip
- jupyter_server
- jupyterlite-core >=0.4.1,<0.5.0
- jupyterlite-xeus>=2.0.0,<3
296 changes: 27 additions & 269 deletions cookbook/Chapter 1 - Reading from a CSV.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"outputs": [],
"source": [
"# because of mixed types we specify dtype to prevent any errors\n",
"complaints = pd.read_csv('../data/311-service-requests.csv', dtype='unicode')"
"complaints = pd.read_csv('./data/311-service-requests.csv', dtype='unicode')"
]
},
{
Expand Down Expand Up @@ -1693,7 +1693,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1707,9 +1707,16 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.9.20"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"outputs": [],
"source": [
"# because of mixed types we specify dtype to prevent any errors\n",
"complaints = pd.read_csv('../data/311-service-requests.csv', dtype='unicode')"
"complaints = pd.read_csv('./data/311-service-requests.csv', dtype='unicode')"
]
},
{
Expand Down Expand Up @@ -1607,7 +1607,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1621,9 +1621,16 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.9.20"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}
],
"source": [
"bikes = pd.read_csv('../data/bikes.csv', sep=';', encoding='latin1', parse_dates=['Date'], dayfirst=True, index_col='Date')\n",
"bikes = pd.read_csv('./data/bikes.csv', sep=';', encoding='latin1', parse_dates=['Date'], dayfirst=True, index_col='Date')\n",
"bikes['Berri 1'].plot()"
]
},
Expand Down Expand Up @@ -628,7 +628,7 @@
}
],
"source": [
"bikes = pd.read_csv('../data/bikes.csv', \n",
"bikes = pd.read_csv('./data/bikes.csv', \n",
" sep=';', encoding='latin1', \n",
" parse_dates=['Date'], dayfirst=True, \n",
" index_col='Date')\n",
Expand All @@ -652,7 +652,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -666,9 +666,16 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.9.20"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -63,7 +63,7 @@
}
],
"source": [
"weather_2012_final = pd.read_csv('../data/weather_2012.csv', index_col='Date/Time')\n",
"weather_2012_final = pd.read_csv('./data/weather_2012.csv', index_col='Date/Time')\n",
"weather_2012_final['Temp (C)'].plot(figsize=(15, 6))"
]
},
Expand All @@ -85,6 +85,15 @@
"Here's an URL template you can use to get data in Montreal. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#downloading via URLS doesn't work in Jupyterlite"
]
},
{
"cell_type": "code",
"execution_count": 15,
Expand All @@ -103,15 +112,15 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#url = url_template.format(month=3, year=2012)\n",
"#weather_mar2012 = pd.read_csv(url, skiprows=15, index_col='Date/Time', parse_dates=True, encoding='latin1', header=True)\n",
"\n",
"# because the url is broken, we use our saved dataframe for now\n",
"weather_mar2012 = pd.read_csv('../data/weather_2012.csv')"
"weather_mar2012 = pd.read_csv('./data/weather_2012.csv')"
]
},
{
Expand Down Expand Up @@ -1905,7 +1914,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1919,9 +1928,16 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.9.20"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
}
],
"source": [
"weather_2012 = pd.read_csv('../data/weather_2012.csv', parse_dates=True, index_col='Date/Time')\n",
"weather_2012 = pd.read_csv('./data/weather_2012.csv', parse_dates=True, index_col='Date/Time')\n",
"weather_2012[:5]"
]
},
Expand Down Expand Up @@ -717,7 +717,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -731,9 +731,16 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.9.20"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
19 changes: 13 additions & 6 deletions cookbook/Chapter 7 - Cleaning up messy data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"metadata": {},
"outputs": [],
"source": [
"requests = pd.read_csv('../data/311-service-requests.csv', dtype='unicode')"
"requests = pd.read_csv('./data/311-service-requests.csv', dtype='unicode')"
]
},
{
Expand Down Expand Up @@ -149,7 +149,7 @@
"outputs": [],
"source": [
"na_values = ['NO CLUE', 'N/A', '0']\n",
"requests = pd.read_csv('../data/311-service-requests.csv', na_values=na_values, dtype={'Incident Zip': str})"
"requests = pd.read_csv('./data/311-service-requests.csv', na_values=na_values, dtype={'Incident Zip': str})"
]
},
{
Expand Down Expand Up @@ -1194,7 +1194,7 @@
"outputs": [],
"source": [
"na_values = ['NO CLUE', 'N/A', '0']\n",
"requests = pd.read_csv('../data/311-service-requests.csv', \n",
"requests = pd.read_csv('./data/311-service-requests.csv', \n",
" na_values=na_values, \n",
" dtype={'Incident Zip': str})"
]
Expand Down Expand Up @@ -1337,7 +1337,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1351,9 +1351,16 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.9.20"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Loading

0 comments on commit ba8d1d3

Please sign in to comment.