Skip to content

Commit b0a9888

Browse files
committed
Minor post-workshop edits
1 parent 7752e2c commit b0a9888

File tree

2 files changed

+106
-96
lines changed

2 files changed

+106
-96
lines changed

README.md

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
- [<span class="toc-section-number">2.17</span> (Optional) Things we didn't talk about](#optional-things-we-didnt-talk-about)
3131
- [<span class="toc-section-number">2.18</span> (Optional) Introspecting on the DataFrame object](#optional-introspecting-on-the-dataframe-object)
3232
- [<span class="toc-section-number">3</span> Building Programs (Week 3)](#building-programs-week-3)
33-
- [<span class="toc-section-number">3.1</span> Notebooks vs Python scripts](#notebooks-vs-python-scripts)
34-
- [<span class="toc-section-number">3.2</span> (Optional) Python from the terminal](#optional-python-from-the-terminal)
35-
- [<span class="toc-section-number">3.3</span> Looping Over Data Sets](#looping-over-data-sets)
36-
- [<span class="toc-section-number">3.4</span> Conditionals](#conditionals)
37-
- [<span class="toc-section-number">3.5</span> Writing Functions](#writing-functions)
33+
- [<span class="toc-section-number">3.1</span> Looping Over Data Sets](#looping-over-data-sets)
34+
- [<span class="toc-section-number">3.2</span> Conditionals](#conditionals)
35+
- [<span class="toc-section-number">3.3</span> Writing Functions](#writing-functions)
36+
- [<span class="toc-section-number">3.4</span> Notebooks vs Python scripts](#notebooks-vs-python-scripts)
37+
- [<span class="toc-section-number">3.5</span> (Optional) Python from the terminal](#optional-python-from-the-terminal)
3838
- [<span class="toc-section-number">3.6</span> (Optional) Use pathlib to write code that works across operating systems](#optional-use-pathlib-to-write-code-that-works-across-operating-systems)
3939
- [<span class="toc-section-number">3.7</span> (Optional) Generic file handling](#optional-generic-file-handling)
4040
- [<span class="toc-section-number">3.8</span> (Optional) Text processing and data cleanup](#optional-text-processing-and-data-cleanup)
@@ -1580,13 +1580,17 @@ data["wealthy"] = high_gdp
15801580
15811581
Capture the results of your filter in a new file, rather than overwriting your original data.
15821582
1583-
``` python
1584-
# Save to a new CSV, preserving your original data
1585-
data.to_csv('gapminder_gdp_europe_grouped.csv')
1583+
1. Create a new subdirectory called "processed" using the editor's file interface.
15861584
1587-
# If you don't want to preserve row names:
1588-
data.to_csv('gapminder_gdp_europe_grouped.csv', index=False)
1589-
```
1585+
2. Save your data as a CSV in the subdirectory
1586+
1587+
``` python
1588+
# Save to a new CSV, preserving your original data
1589+
data.to_csv('gapminder_gdp_europe_grouped.csv')
1590+
1591+
# If you don't want to preserve row names:
1592+
data.to_csv('gapminder_gdp_europe_grouped.csv', index=False)
1593+
```
15901594
15911595
## Working with missing data
15921596
@@ -2000,47 +2004,6 @@ Scikit-Learn documentation: <https://scikit-learn.org/stable/>
20002004
20012005
# Building Programs (Week 3)
20022006
2003-
## Notebooks vs Python scripts
2004-
2005-
### Differences between .ipynb and .py
2006-
2007-
1. Export notebook to .py file
2008-
2. Move .py file into data directory
2009-
3. Compare files in TextEdit/Notepad
2010-
2011-
### Workflow differences between notebooks and scripts
2012-
2013-
Broadly, a trade-off between managing big code bases and making it easy to experiment. See: <https://github.com/elliewix/Ways-Of-Installing-Python/blob/master/ways-of-installing.md#why-do-you-need-a-specific-tool>
2014-
2015-
1. Interactive testing and debugging
2016-
2. Graphics integration
2017-
3. Version control
2018-
4. Remote scripts
2019-
2020-
## (Optional) Python from the terminal
2021-
2022-
1. Python is an interactive interpreter (REPL)
2023-
2024-
``` bash
2025-
python
2026-
```
2027-
2028-
2. Python is a command line program
2029-
2030-
``` python
2031-
# hello.py
2032-
print("Hello!")
2033-
```
2034-
2035-
``` bash
2036-
python hello.py
2037-
```
2038-
2039-
3. (Optional) Python programs can accept command line arguments as inputs
2040-
2041-
1. List of command line inputs: `sys.argv` (<https://docs.python.org/3/library/sys.html#sys.argv>)
2042-
2. Utility for working with arguments: `argparse` (<https://docs.python.org/3/library/argparse.html>)
2043-
20442007
## Looping Over Data Sets
20452008
20462009
### File paths as an example of increasing abstraction in program development
@@ -2349,8 +2312,10 @@ print_greeting()
23492312
23502313
``` python
23512314
def print_date(year, month, day):
2352-
joined = '/'.join([year, month, day])
2353-
print(joined)
2315+
"""Print the formatted date. This works with strings or integers."""
2316+
2317+
formatted_date = f"{year}/{month}/{day}"
2318+
print(formatted_date)
23542319
23552320
print_date(1871, 3, 19)
23562321
```
@@ -2460,6 +2425,47 @@ all_data.to_csv("gapminder_mean_all.csv", index=False)
24602425
24612426
<https://matplotlib.org/stable/gallery/mplot3d/lorenz_attractor.html>
24622427
2428+
## Notebooks vs Python scripts
2429+
2430+
### Differences between .ipynb and .py
2431+
2432+
1. Export notebook to .py file
2433+
2. Move .py file into data directory
2434+
3. Compare files in TextEdit/Notepad
2435+
2436+
### Workflow differences between notebooks and scripts
2437+
2438+
Broadly, a trade-off between managing big code bases and making it easy to experiment. See: <https://github.com/elliewix/Ways-Of-Installing-Python/blob/master/ways-of-installing.md#why-do-you-need-a-specific-tool>
2439+
2440+
1. Interactive testing and debugging
2441+
2. Graphics integration
2442+
3. Version control
2443+
4. Remote scripts
2444+
2445+
## (Optional) Python from the terminal
2446+
2447+
1. Python is an interactive interpreter (REPL)
2448+
2449+
``` bash
2450+
python
2451+
```
2452+
2453+
2. Python is a command line program
2454+
2455+
``` python
2456+
# hello.py
2457+
print("Hello!")
2458+
```
2459+
2460+
``` bash
2461+
python hello.py
2462+
```
2463+
2464+
3. (Optional) Python programs can accept command line arguments as inputs
2465+
2466+
1. List of command line inputs: `sys.argv` (<https://docs.python.org/3/library/sys.html#sys.argv>)
2467+
2. Utility for working with arguments: `argparse` (<https://docs.python.org/3/library/argparse.html>)
2468+
24632469
## (Optional) Use pathlib to write code that works across operating systems
24642470
24652471
1. Pathlib provides cross-platform path objects

README.org

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,13 +1447,15 @@ print(z_bool)
14471447

14481448
** Write output
14491449
Capture the results of your filter in a new file, rather than overwriting your original data.
1450-
#+BEGIN_SRC python
1451-
# Save to a new CSV, preserving your original data
1452-
data.to_csv('gapminder_gdp_europe_grouped.csv')
1450+
1. Create a new subdirectory called "processed" using the editor's file interface.
1451+
2. Save your data as a CSV in the subdirectory
1452+
#+BEGIN_SRC python
1453+
# Save to a new CSV, preserving your original data
1454+
data.to_csv('gapminder_gdp_europe_grouped.csv')
14531455

1454-
# If you don't want to preserve row names:
1455-
data.to_csv('gapminder_gdp_europe_grouped.csv', index=False)
1456-
#+END_SRC
1456+
# If you don't want to preserve row names:
1457+
data.to_csv('gapminder_gdp_europe_grouped.csv', index=False)
1458+
#+END_SRC
14571459

14581460
** Working with missing data
14591461
*** By default, most numerical operations ignore missing data
@@ -1879,39 +1881,6 @@ wine.rename(columns={"color_intensity": "ci"})
18791881
#+END_SRC
18801882

18811883
* Building Programs (Week 3)
1882-
** Notebooks vs Python scripts
1883-
*** Differences between .ipynb and .py
1884-
1. Export notebook to .py file
1885-
2. Move .py file into data directory
1886-
3. Compare files in TextEdit/Notepad
1887-
1888-
*** Workflow differences between notebooks and scripts
1889-
Broadly, a trade-off between managing big code bases and making it easy to experiment. See: https://github.com/elliewix/Ways-Of-Installing-Python/blob/master/ways-of-installing.md#why-do-you-need-a-specific-tool
1890-
1. Interactive testing and debugging
1891-
2. Graphics integration
1892-
3. Version control
1893-
4. Remote scripts
1894-
1895-
** (Optional) Python from the terminal
1896-
1. Python is an interactive interpreter (REPL)
1897-
#+BEGIN_SRC bash
1898-
python
1899-
#+END_SRC
1900-
1901-
2. Python is a command line program
1902-
#+BEGIN_SRC python
1903-
# hello.py
1904-
print("Hello!")
1905-
#+END_SRC
1906-
1907-
#+BEGIN_SRC bash
1908-
python hello.py
1909-
#+END_SRC
1910-
1911-
3. (Optional) Python programs can accept command line arguments as inputs
1912-
1. List of command line inputs: ~sys.argv~ (https://docs.python.org/3/library/sys.html#sys.argv)
1913-
2. Utility for working with arguments: ~argparse~ (https://docs.python.org/3/library/argparse.html)
1914-
19151884
** Looping Over Data Sets
19161885
*** File paths as an example of increasing abstraction in program development
19171886
1. File paths as literal strings
@@ -2202,8 +2171,10 @@ print_greeting()
22022171
1. Positional arguments
22032172
#+BEGIN_SRC python
22042173
def print_date(year, month, day):
2205-
joined = '/'.join([year, month, day])
2206-
print(joined)
2174+
"""Print the formatted date. This works with strings or integers."""
2175+
2176+
formatted_date = f"{year}/{month}/{day}"
2177+
print(formatted_date)
22072178

22082179
print_date(1871, 3, 19)
22092180
#+END_SRC
@@ -2301,6 +2272,39 @@ all_data.to_csv("gapminder_mean_all.csv", index=False)
23012272
*** (Optional) A worked example: The Lorenz attractor
23022273
https://matplotlib.org/stable/gallery/mplot3d/lorenz_attractor.html
23032274

2275+
** Notebooks vs Python scripts
2276+
*** Differences between .ipynb and .py
2277+
1. Export notebook to .py file
2278+
2. Move .py file into data directory
2279+
3. Compare files in TextEdit/Notepad
2280+
2281+
*** Workflow differences between notebooks and scripts
2282+
Broadly, a trade-off between managing big code bases and making it easy to experiment. See: https://github.com/elliewix/Ways-Of-Installing-Python/blob/master/ways-of-installing.md#why-do-you-need-a-specific-tool
2283+
1. Interactive testing and debugging
2284+
2. Graphics integration
2285+
3. Version control
2286+
4. Remote scripts
2287+
2288+
** (Optional) Python from the terminal
2289+
1. Python is an interactive interpreter (REPL)
2290+
#+BEGIN_SRC bash
2291+
python
2292+
#+END_SRC
2293+
2294+
2. Python is a command line program
2295+
#+BEGIN_SRC python
2296+
# hello.py
2297+
print("Hello!")
2298+
#+END_SRC
2299+
2300+
#+BEGIN_SRC bash
2301+
python hello.py
2302+
#+END_SRC
2303+
2304+
3. (Optional) Python programs can accept command line arguments as inputs
2305+
1. List of command line inputs: ~sys.argv~ (https://docs.python.org/3/library/sys.html#sys.argv)
2306+
2. Utility for working with arguments: ~argparse~ (https://docs.python.org/3/library/argparse.html)
2307+
23042308
** (Optional) Use pathlib to write code that works across operating systems
23052309
1. Pathlib provides cross-platform path objects
23062310
#+BEGIN_SRC python
@@ -3388,7 +3392,7 @@ Do this if you want code syntax highlighting and a table of contents on Github.
33883392
#+BEGIN_SRC bash
33893393
pandoc -f org -t gfm --toc --toc-depth=2 --wrap=none -N -s README.org -o README.md
33903394

3391-
# Add section headers
3395+
# Add section headers. These don't appear to work as links on the github.io website
33923396
pandoc -f org -t gfm --toc --toc-depth=2 --wrap=none -s --lua-filter ./pandoc-section-number-filter.lua README.org -o README.md
33933397
#+END_SRC
33943398

0 commit comments

Comments
 (0)