Skip to content

Commit bcf4f06

Browse files
committed
Small content updates.
1 parent 7fde0fc commit bcf4f06

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

notebooks/0b_anaconda.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@
506506
"1. The cell structure is flexible, but it will allow you to do things out of order, and anything you import or assign is still there, even if you change the code. To avoid this issue:\n",
507507
" 1. Purposefully try to keep your code in the order that it should be run.\n",
508508
" 1. Periodically, use \"Restart Kernel and Run All Cells...\" to make sure that your notebook runs in order.\n",
509-
"1. It is not ideal for version controlled environments like Github. If you want to version control projects, you may find yourself moving code into `.py` files and using Jupyter for prototyping. Otherwise, this may not be a big concern.\n",
510-
"1. It is not a good format for a manuscript (unlike [R notebooks](https://bookdown.org/yihui/rmarkdown/notebook.html)). However, it is much more capable.\n",
509+
"1. It is not ideal for version controlled environments like Github. If you want to version control projects, you may find yourself moving code into `.py` files and using Jupyter for prototyping, or you might remove cell outputs before committing (like the course resposity does). Otherwise, this may not be a big concern.\n",
510+
"1. It is not a good format for a manuscript (unlike [R notebooks](https://bookdown.org/yihui/rmarkdown/notebook.html)). However, it is much more capable. For something more like R notebooks, [Quarto](https://quarto.org) is shaping up to be a high-quality Python alternative.\n",
511511
"\n",
512512
"Overall, the Jupyter notebook is a great tool.\n",
513513
"Once you have some experience using them, you may find them fairly natural to work with."
@@ -615,7 +615,7 @@
615615
"name": "python",
616616
"nbconvert_exporter": "python",
617617
"pygments_lexer": "ipython3",
618-
"version": "3.11.3"
618+
"version": "3.11.4"
619619
},
620620
"vscode": {
621621
"interpreter": {

notebooks/1a_python2.ipynb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@
4747
" return (temp_f - 32) * 5 / 9"
4848
]
4949
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"There are names for the parts of a function.\n",
55+
"\n",
56+
"- **Defining a function.** We use the keyword `def` to define a function.\n",
57+
"- **Function name.** Following the `def` keyword, we give the function a name. In this example, it is `f_to_c`.\n",
58+
"- **Parameter(s).** After the name, we have a set of parentheses that contains zero or more parameters. This is how we define what the function expects as input.\n",
59+
"- **Argument(s).** When we call the function after defining it, the values to pass in to the parameters are called the arguments. You will sometimes hear \"parameters\" and \"arguments\" used interchangeably (including from me; old habits die hard), but they are technically distinct.\n",
60+
"- **Body.** After the colon, we indent the body of the function, which is one or more lines of code providing the procedure to be executed.\n",
61+
"- **Return.** We use the `return` keyword to return a value back to where the function was called. This is optional to use, and `None` is returned if a return value is not otherwise provided.\n",
62+
"\n",
63+
"Note: Using `def` only defines the function and points the specified name to the function object. The code itself does not run until called."
64+
]
65+
},
5066
{
5167
"cell_type": "code",
5268
"execution_count": null,

notebooks/1c_visualization.ipynb

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,65 @@
504504
"source": [
505505
"# 1-2 code"
506506
]
507+
},
508+
{
509+
"cell_type": "markdown",
510+
"metadata": {},
511+
"source": [
512+
"# Bonus Content\n",
513+
"\n",
514+
"Did you notice that, once we figured out the height, width, and template that we wanted, we ended up reusing those arguments again and again?\n",
515+
"There is a way to capture those and reuse them.\n",
516+
"We use a dictionary and [dictionary unpacking](https://docs.python.org/3/tutorial/controlflow.html?highlight=unpack%20dictionary#unpacking-argument-lists).\n",
517+
"See the example below."
518+
]
519+
},
520+
{
521+
"cell_type": "code",
522+
"execution_count": null,
523+
"metadata": {},
524+
"outputs": [],
525+
"source": [
526+
"fig_b03 = px.line(\n",
527+
" vis,\n",
528+
" x=\"year\",\n",
529+
" y=\"vis\",\n",
530+
" title=\"WSJ Coverage by Firm-year\",\n",
531+
" color=\"ticker\",\n",
532+
" template=\"plotly_dark\",\n",
533+
" width=800,\n",
534+
" height=600,\n",
535+
")\n",
536+
"\n",
537+
"fig_b03.show()"
538+
]
539+
},
540+
{
541+
"cell_type": "code",
542+
"execution_count": null,
543+
"metadata": {},
544+
"outputs": [],
545+
"source": [
546+
"GRAPH_FORMAT = {\"template\": \"plotly_dark\", \"width\": 800, \"height\": 600}\n",
547+
"\n",
548+
"fig_b03a = px.line(\n",
549+
" vis,\n",
550+
" x=\"year\",\n",
551+
" y=\"vis\",\n",
552+
" title=\"WSJ Coverage by Firm-year\",\n",
553+
" color=\"ticker\",\n",
554+
" **GRAPH_FORMAT,\n",
555+
")\n",
556+
"\n",
557+
"fig_b03a.show()"
558+
]
559+
},
560+
{
561+
"cell_type": "markdown",
562+
"metadata": {},
563+
"source": [
564+
"A key benefit of extracting our favorite formatiing options this way is that we can change all of our graphs by making a single change to a single dictionary."
565+
]
507566
}
508567
],
509568
"metadata": {
@@ -526,7 +585,7 @@
526585
"name": "python",
527586
"nbconvert_exporter": "python",
528587
"pygments_lexer": "ipython3",
529-
"version": "3.11.3"
588+
"version": "3.11.4"
530589
},
531590
"vscode": {
532591
"interpreter": {

notebooks/2b_retrieval1.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@
460460
"name": "python",
461461
"nbconvert_exporter": "python",
462462
"pygments_lexer": "ipython3",
463-
"version": "3.11.3"
463+
"version": "3.11.4"
464464
},
465465
"vscode": {
466466
"interpreter": {

notebooks/2c_retrieval2.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"outputs": [],
146146
"source": [
147147
"start = datetime.datetime(2012, 1, 1)\n",
148-
"end = datetime.datetime(2023, 2, 28)\n",
148+
"end = datetime.datetime(2023, 12, 31)\n",
149149
"\n",
150150
"fred_gs10 = pdr.DataReader(\"GS10\", \"fred\", start, end).reset_index()\n",
151151
"fred_gs10.head()"
@@ -228,7 +228,7 @@
228228
"name": "python",
229229
"nbconvert_exporter": "python",
230230
"pygments_lexer": "ipython3",
231-
"version": "3.11.3"
231+
"version": "3.11.4"
232232
},
233233
"vscode": {
234234
"interpreter": {

0 commit comments

Comments
 (0)