-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python screenshots and chapter plan
- Loading branch information
1 parent
959cc35
commit ac3c8a8
Showing
25 changed files
with
475 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ engine: knitr | |
**Software and packages** | ||
|
||
- `Python` [@python] | ||
- `datetime>=5.5` | ||
- `uv` | ||
- `polars` | ||
|
||
|
@@ -26,11 +27,21 @@ Knowing `R` will allow you to pick up `Python` for data science quickly. The mai | |
|
||
## Python, VS Code, and uv | ||
|
||
We could use `Python` within RStudio, but it makes sense to use what is used by the community more broadly, which is VS Code. You can download VS Code for free [here](https://code.visualstudio.com) and then install it. If you have difficulties with this, then in the same way we started with Posit Cloud and the shifted to our local machine, you could initially use Google Colab [here](https://colab.google). | ||
We could use `Python` within RStudio, but another option is to use what is used by the community more broadly, which is VS Code. You can download VS Code for free [here](https://code.visualstudio.com) and then install it. If you have difficulties with this, then in the same way we started with Posit Cloud and the shifted to our local machine, you could initially use Google Colab [here](https://colab.google). | ||
|
||
Open VS Code, and open a new Terminal to install `uv`, which is a Python package manager, analogous to CRAN: `curl -LsSf https://astral.sh/uv/install.sh | sh`. | ||
Open VS Code (@fig-vscodesetup-a), and open a new Terminal: Terminal -> New Terminal (@fig-vscodesetup-b). We can then install `uv`, which is a Python package manager, by putting `curl -LsSf https://astral.sh/uv/install.sh | sh` into the Terminal and pressing "return/enter" afterwards (@fig-vscodesetup-c). Finally, to install Python we can use `uv` by putting `uv python install` into that Terminal and pressing "return/enter" afterwards (@fig-vscodesetup-d). | ||
|
||
Then we can use `uv` in that Terminal to install Python: `uv python install`. | ||
::: {#fig-vscodesetup layout-ncol="2"} | ||
{#fig-vscodesetup-a width="50%"} | ||
|
||
{#fig-vscodesetup-b width="50%"} | ||
|
||
{#fig-vscodesetup-c width="50%"} | ||
|
||
{#fig-vscodesetup-d width="50%"} | ||
|
||
Opening VS Code and a new terminal and then installing uv and Python | ||
::: | ||
|
||
## Getting started | ||
|
||
|
@@ -101,9 +112,9 @@ After we have modified and saved `hello.py` we can run it with `uv run` in exact | |
|
||
At this point we should close VS Code. We want to re-open it to make sure that our project environment is working as it needs to. In VS Code, a project is a self-contained folder. You can open a folder with "File" -> "Open Folder..." and then select the relevant folder, in this case "shelter_usage". You should then be able to re-run `uv run hello.py` and it should work. | ||
|
||
### Simulating data | ||
### Plan | ||
|
||
We would like to more thoroughly simulate the dataset that we are interested in. We first used this dataset in @sec-fire-hose, but as a reminder, for each day, for each shelter, there is a number of people that used the shelter. So the dataset that we want to simulate is something like @fig-python_torontohomeless-data and we are wanting to create a table of average daily number of occupied beds each month, along the lines of @fig-python_torontohomeless-table. | ||
We first used this dataset in @sec-fire-hose, but as a reminder, for each day, for each shelter, there is a number of people that used the shelter. So the dataset that we want to simulate is something like @fig-python_torontohomeless-data and we are wanting to create a table of average daily number of occupied beds each month, along the lines of @fig-python_torontohomeless-table. | ||
|
||
::: {#fig-python_torontohomeless layout-ncol="2"} | ||
{#fig-python_torontohomeless-data width="50%"} | ||
|
@@ -113,7 +124,9 @@ We would like to more thoroughly simulate the dataset that we are interested in. | |
Sketches of a dataset and table related shelter usage in Toronto | ||
::: | ||
|
||
We will use `polars` to provide a dataframe to store our simulated results, so we should add this to our environment with `uv add`. | ||
### Simulate | ||
|
||
We would like to more thoroughly simulate the dataset that we are interested in. We will use `polars` to provide a dataframe to store our simulated results, so we should add this to our environment with `uv add`. | ||
|
||
```{bash} | ||
#| eval: false | ||
|
@@ -131,7 +144,7 @@ Create a new Python file called `00-simulate_data.py`. | |
#| message: false | ||
#### Preamble #### | ||
# Purpose: Simulates a dataset of the number of people in a bed, in each shelter, on each day. | ||
# Purpose: Simulates a dataset of daily shelter usage | ||
# Author: Rohan Alexander | ||
# Date: 12 November 2024 | ||
# Contact: [email protected] | ||
|
@@ -182,23 +195,15 @@ print(data) | |
|
||
Write tests | ||
|
||
### Acquire | ||
|
||
Download data | ||
|
||
Apply tests | ||
|
||
Manipulate the data | ||
|
||
Make a graph | ||
|
||
Add it all into Quarto | ||
### Explore | ||
|
||
Add GitHub to VS code. Why environments. | ||
|
||
|
||
|
||
|
||
|
||
## Manipulating data | ||
Manipulate the data | ||
|
||
```{python} | ||
#| eval: false | ||
|
@@ -210,7 +215,7 @@ import polars as pl | |
``` | ||
|
||
|
||
## Making graphs | ||
Make a graph | ||
|
||
```{python} | ||
#| eval: false | ||
|
@@ -222,14 +227,48 @@ import matplotlib.pyplot as plt | |
``` | ||
|
||
|
||
### Share | ||
|
||
Add it all into Quarto | ||
|
||
Add GitHub to VS code. Why environments. | ||
|
||
|
||
|
||
## Python | ||
|
||
For loops | ||
|
||
List comprehensions | ||
|
||
## Making graphs | ||
|
||
matplotlib | ||
|
||
seaborn | ||
|
||
|
||
## Exploring polars | ||
|
||
### Importing data | ||
|
||
### Dataset manipulation with joins and pivots | ||
|
||
### String manipulation | ||
|
||
### Factor variables | ||
|
||
|
||
|
||
## Exercises | ||
|
||
### Practice {.unnumbered} | ||
|
||
Free Replit "100 Days of Code" Python [course](https://replit.com/learn/100-days-of-python). | ||
|
||
### Quiz {.unnumbered} | ||
|
||
|
||
### Task {.unnumbered} | ||
|
||
Free Replit "100 Days of Code" Python [course](https://replit.com/learn/100-days-of-python). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.