-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
579 additions
and
424 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
Binary file removed
BIN
-66.2 KB
_images/505bd437054fea3528fab8c017979df97799f974db4685a6ffd9c505ca20398c.png
Binary file not shown.
Binary file added
BIN
+67.5 KB
_images/5796daf81770581140056f92b0ab38cc6a59891d26a1403ee0e9a1162a70cc01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+66.3 KB
_images/bdd25214bdabcd4676c1fbd021219600d0fcc107ec949c1cd1a82b0b4a6e245f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-66.7 KB
_images/c36a6214dbfd974846acdf77add6921e8d3cff65cafae45b310c7fcda8b9466c.png
Binary file not shown.
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 |
---|---|---|
|
@@ -14,24 +14,35 @@ kernelspec: | |
|
||
# Week 00: Start here | ||
|
||
MATH 131: Introduction to Python is a 1 unit, 5 week course offered at Chico | ||
State through the Department of Mathematics and Statistics. The course consists | ||
Lessons and Assignments. We will learn to code in the programming language | ||
Python using Google Colab notebooks. Lessons, Assignments, and Google Colab | ||
notebooks are discussed in more detail below, and there is a link to a Google | ||
Colab notebook that better introduces this programming environment. | ||
MATH 131: Introduction to Python is a 1 unit, 5 week course offered at | ||
Chico State through the Department of Mathematics and Statistics. The | ||
course consists of Lessons, with accompanying Notes, and Assignments. | ||
We will learn to code in the programming language Python using Google | ||
Colab notebooks. | ||
|
||
### Lessons | ||
Lessons are the webpages found on this website, named after each week | ||
of the course. Lessons contain the explanations of what's to come in | ||
the Assignments. You are currently reading the Lesson associated with | ||
Week 00. There is one Lesson for each of the five weeks of this | ||
course. | ||
|
||
Lessons found on this website. Lessons contain the explanations of what's to | ||
come in the assignments. Examples and all. | ||
The Lessons have associated Notes. Each Note is a Google | ||
Colab notebook, e.g. Week 01 Notes. Notes are par-baked Colab | ||
notebooks that are meant to provide you with a space to follow along | ||
with the programming in the Lesson. Google Colab notebooks are | ||
discussed in more detail below. | ||
|
||
### Assignments | ||
Each week has an Assignment, e.g. Week 02 Assignment, starting with | ||
Week 01. You are responsible for completing the Assignments | ||
throughout the course. Each Lesson will have a link to the associated | ||
Assignment for you to complete. | ||
|
||
For assignments, we'll use Google Colab with your [email protected] | ||
account (same password as your [email protected] account). | ||
For assignments, we will use Google Colab with your | ||
[email protected] account (same password as your | ||
[email protected] account). | ||
|
||
### Google Colab | ||
|
||
## Google Colab | ||
|
||
[Google Colab](https://colab.research.google.com) provides a notebook | ||
environment where the user can develop a reproducible document that blends text | ||
|
@@ -41,14 +52,16 @@ programming. By combining text and code, you can walk (via text) your audience | |
through an analysis (usually via code and/or math), showing the exact code you | ||
used to draw any conclusions about the data or otherwise. | ||
|
||
We will use Google Colab for free, as part of your campus Google account | ||
[email protected]. The free aspect means we'll have to deal with some | ||
issues that don't otherwise come about if we were to install Python on our own | ||
personal machines. I, Edward, have made the active choice to use Google Colab | ||
instead of teaching you how to install Python on your personal machine, | ||
because I believe we can get started faster this way. If you want to follow | ||
along with this course using different tools, please see the details on the | ||
page [Week 06 and beyond][and-beyond.md]. | ||
We will use Google Colab for free, as part of your campus Google | ||
account [email protected]. The free aspect means we'll have | ||
to deal with some issues that don't otherwise come about if we were to | ||
install Python on our own personal machines. I, Edward, have made the | ||
active choice to try Google Colab instead of teaching you how to | ||
install Python on your personal machine, because I believe we can get | ||
started faster this way. If you want to follow along with this course | ||
using different tools, and you understand the consequences you face | ||
for doing so, please see your options on the page [Week 06 and | ||
beyond][./and-beyond.md]. | ||
|
||
From here, there's really no better way to learn about Google Colab than to go | ||
touch it. Here's a link to [the Colab notebook associated with Week 00: Start | ||
|
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 |
---|---|---|
|
@@ -12,6 +12,8 @@ kernelspec: | |
name: python3 | ||
--- | ||
|
||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200" /> | ||
|
||
# Week 04: Filling in some details | ||
|
||
## Learning outcomes | ||
|
@@ -27,7 +29,7 @@ After completing this lesson, you will be able to | |
## Preparation | ||
|
||
To follow along with this Lesson, please open the Colab notebook | ||
[Week-04-Notes](#TODO). The first code cell of this notebook calls to | ||
[Week-04-Notes](https://colab.research.google.com/drive/1FvGDi4MQxNzVOJRk6w07RWy3nnGNNF2K?usp=sharing). The first code cell of this notebook calls to | ||
the remote computer, on which the notebook is running, and installs | ||
the necessary packages. For practice, you are repsonible for | ||
importing the necessary packages. | ||
|
@@ -38,17 +40,18 @@ In this section, we cover some details about customizing a plotnine plot. This | |
lesson will not explore all available options, nor are you expected to memorize | ||
all the details we cover. This lesson is intended to be an introduction to the | ||
types of things you can easily change on a plotnine plot. For details and/or | ||
reference material on computer software, you should consult the plotnine | ||
documentation. | ||
reference material on computer software, you should consult the [plotnine | ||
documentation](https://plotnine.readthedocs.io/en/stable/api.html). | ||
|
||
Let's continue developing the plot we started at the end of [Week | ||
03](../week-03.md). Our goal is to display information about the mean total | ||
amount of sleep mamals (in our dataset) get, where the data are grouped by their | ||
`vore` status. This is a task for aggregating: group by `vore` and summarize | ||
with the function `np.mean`. Since the mean of any dataset is random, as part | ||
of the random sampling of the data, we should also calculate and display the | ||
error in our estimate associated with the mean. That is, we should display a | ||
confidence interval for the mean. | ||
03](aggregating). Our goal is to display information about the mean | ||
total amount of sleep mamals (in our dataset) get, where the data are | ||
grouped by their `vore` status. This is a task for aggregating: group | ||
by `vore` and summarize `sleep_total` with the function `np.mean`. | ||
Since the mean of any dataset is random, as part of the random | ||
sampling of the data, we should also calculate and display the error | ||
in our estimate associated with the mean. That is, we should display | ||
a confidence interval for the mean. | ||
|
||
```{code-cell} | ||
import numpy as np | ||
|
@@ -91,7 +94,7 @@ odf["lb"] = odf["mean"] - 1.96 * odf["se"] | |
|
||
Since plotnine plots are created by adding layers of information, let's get | ||
started by creating the variable `p` to hold our plot as we build it up piece by | ||
piece. Below is the code we used from [Week 03](../week-03.md). | ||
piece. Below is the code we used from [Week 03](aggregating). | ||
|
||
|
||
```{code-cell} | ||
|
@@ -155,7 +158,7 @@ information in the data are contained. | |
By specifying a categorical variable for the keyword argument `color` within | ||
`aes`, the jittered points will show up in unique colors for each category of | ||
the variable specified, `vore` in this case. Further, a legend will | ||
automatically be displayed. Change the category names of the variable `vore` is | ||
automatically be displayed. Changing the category names of the variable `vore` is | ||
best done by renaming the categories, as in [Week 02: Categorical | ||
variables](categorical-variables), but we can easily change the | ||
legend title from plotnine. | ||
|
@@ -244,11 +247,6 @@ The main reason behind this is that file paths can be confusing at | |
first. And so we've delayed this topic until near the end. | ||
Invariably, though, you will need to load your own dataset. | ||
|
||
To help you learn about file paths, we have set up a Colab notebook | ||
specific for practicing file paths. Please follow along in the Colab | ||
notebook | ||
[file-paths](https://colab.research.google.com/drive/12q0ostmi7b7LUFOv6srC2xBuN7y7Gz9g?usp=sharing). | ||
|
||
### directories | ||
|
||
All computers organize their files in **directories**, which are sometimes | ||
|
@@ -348,7 +346,7 @@ In a .csv file, the entire table of data above would look as follows. | |
|
||
```{code-cell} | ||
--- | ||
tags: [raises-exception] | ||
tags: [raises-exception, remove-output] | ||
--- | ||
type,size,color | ||
|
@@ -508,8 +506,50 @@ file into a DataFrame, just as we worked with beginning in Week 01. | |
|
||
```{code-cell} | ||
--- | ||
tags: [raises-exception] | ||
tags: [raises-exception, remove-output] | ||
--- | ||
df = pd.read_csv("./path/to/your/data.csv") | ||
``` | ||
|
||
#### your data in a Google Colab notebook | ||
|
||
When dealing with your own data while working in a Google Colab | ||
notebook, you have to remember that the computer on which your | ||
notebook runs is not the computer in front of you. This means, to | ||
read data into Python, you need to *upload* any dataset onto the Colab | ||
notebook computer. | ||
|
||
To upload a dataset to the notebook computer, click on the folder | ||
looking icon, <span class="material-symbols-outlined">folder</span>, | ||
near the top left of the Colab notebook within your browser. | ||
Confusingly, the tooltip you get when hovering over the folder icon | ||
reads Files. Then click the upload file icon, <span | ||
class="material-symbols-outlined">upload_file</span>, to upload the | ||
dataset you want. | ||
|
||
Let's say the file you uploaded is named `research_data.csv`. If | ||
upload your dataset into the current working directory on the notebook | ||
computer, then the file path will be `./research_data.csv`, and the | ||
code to read this file into Python, using Pandas, is | ||
|
||
```{code-cell} | ||
--- | ||
tags: [raises-exception, remove-output] | ||
--- | ||
df = pd.read_csv("./research_data.csv") | ||
``` | ||
|
||
If, before uploading your dataset, you created a new directory named | ||
`data`, and then you uploaded `research_data.csv` into the directory | ||
`data`, the file path will be `./data/research_data.csv`, and the code | ||
to read this file into Python, using Pandas, is | ||
|
||
```{code-cell} | ||
--- | ||
tags: [raises-exception, remove-output] | ||
--- | ||
df = pd.read_csv("/path/to/your/data.csv") | ||
df = pd.read_csv("./data/research_data.csv") | ||
``` |
Oops, something went wrong.