Skip to content

Commit

Permalink
Render toc-less
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 25, 2024
1 parent 112ab45 commit a4ad23b
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 176 deletions.
34 changes: 17 additions & 17 deletions docs/no_toc/01-intro-to-computing.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Now, we will get to the basics of programming grammar.

- **Expressions** are be built out of **operations** or **functions**.

- Functions and operations take in **data types**, do something with them, and return another data type.
- Functions and operations take in **data types** as inputs, do something with them, and **return** another data type as ouput.

- We can combine multiple expressions together to form more complex expressions: an expression can have other expressions nested inside it.

Expand Down Expand Up @@ -148,17 +148,6 @@ add(18, add(21, 65))

Remember that the Python language is supposed to help us understand what we are writing in code easily, lending to *readable* code. Therefore, it is sometimes useful to come up with operations that is easier to read. (Most functions in Python are stored in a collection of functions called **modules** that needs to be loaded. The `import` statement gives us permission to access the functions in the module "operator".)

### Data types

Here are some common data types we will be using in this course.

| Data type name | **Data type shorthand** | **Examples** |
|----------------|:-----------------------:|:-----------------------:|
| Integer | int | 2, 4 |
| Float | float | 3.5, -34.1009 |
| String | str | "hello", "234-234-8594" |
| Boolean | bool | True, False |

### Function machine schema

A nice way to summarize this first grammar structure is using the function machine schema, way back from algebra class:
Expand All @@ -171,6 +160,17 @@ Here are some aspects of this schema to pay attention to:

- A function can have different kinds of inputs and outputs - it doesn't need to be numbers. In the `len()` function, the input is a String, and the output is an Integer. We will see increasingly complex functions with all sorts of different inputs and outputs.

### Data types

Here are some common data types we will be using in this course.

| Data type name | **Data type shorthand** | **Examples** |
|----------------|:-----------------------:|:-----------------------:|
| Integer | int | 2, 4 |
| Float | float | 3.5, -34.1009 |
| String | str | "hello", "234-234-8594" |
| Boolean | bool | True, False |

## Grammar Structure 2: Storing data types in the Variable Environment

To build up a computer program, we need to store our returned data type from our expression somewhere for downstream use. We can assign a variable to it as follows:
Expand Down Expand Up @@ -232,7 +232,7 @@ Let's look at functions a little bit more formally: A function has a **function
>
> The output of functions is called the **returned value**.
Often, we will use multiple functions in a nested way, and it is important to understand how the Python console understand the order of operation. We can also use paranthesis to change the order of operation. Think about what the Python is going to do step-by--step in the lines of code below:
Often, we will use multiple functions in a nested way, and it is important to understand how the Python console understand the order of operation. We can also use parenthesis to change the order of operation. Think about what the Python is going to do step-by--step in the lines of code below:


``` python
Expand Down Expand Up @@ -318,11 +318,11 @@ And there is an operational equivalent:

We will mostly look at functions with input arguments and return types in this course, but not all functions need to have input arguments and output return. Let's look at some examples of functions that don't always have an input or output:

| Function call | What it takes in | What it does | Returns |
| Function call | What it takes in | What it does | Returns |
|----------------|----------------|-------------------------|----------------|
| [`pow(a, b)`](https://docs.python.org/3/library/functions.html#pow) | integer `a`, integer `b` | Raises `a` to the `b`th power. | Integer |
| [`print(x)`](https://docs.python.org/3/library/functions.html#print) | any data type `x` | Prints out the value of `x` to the console. | None |
| [`dir()`](https://docs.python.org/3/library/functions.html#dir) | Nothing | Gives a list of all the variables defined in the environment. | List |
| [`pow(a, b)`](https://docs.python.org/3/library/functions.html#pow) | integer `a`, integer `b` | Raises `a` to the `b`th power. | Integer |
| [`time.sleep(x)`](https://docs.python.org/3/library/time.html#time.sleep) | Integer `x` | Waits for `x` seconds. | None |
| [`dir()`](https://docs.python.org/3/library/functions.html#dir) | Nothing | Gives a list of all the variables defined in the environment. | List |

## Tips on writing your first code

Expand Down
74 changes: 48 additions & 26 deletions docs/no_toc/02-data-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,7 @@ chrNum[1:3]
## [3, 1]
```

If you want to access everything but the first three elements of `chrNum`:


``` python
chrNum[3:]
```

```
## [2, 2]
```

Here, the stop index number was not specificed. When the start or stop index is *not* specified, it implies that you are subsetting starting the from the beginning of the list or subsetting to the end of the list, respectively:
Another way of accessing the first 3 elements of `chrNum`:


``` python
Expand All @@ -89,33 +78,36 @@ chrNum[:3]
## [2, 3, 1]
```

Here, the start index number was not specified. When the start or stop index is *not* specified, it implies that you are subsetting starting the from the beginning of the list or subsetting to the end of the list, respectively. Here's another example, using negative indicies to count from 3 elements from the end of the list:


``` python
chrNum[3:]
chrNum[-3:]
```

```
## [2, 2]
## [1, 2, 2]
```

There are other popular uses of the slice operator `:`, such as negative indicies to count from the end of a list, or subsetting with a fixed increment. You can find more discussion of list slicing [here](https://wesmckinney.com/book/python-builtin#list_slicing).
You can find more discussion of list slicing, using negative indicies and incremental slicing, [here](https://towardsdatascience.com/the-basics-of-indexing-and-slicing-python-lists-2d12c90a94cf).

## Objects in Python

The list data structure has an organization and functionality that metaphorically represents a pen-and-paper list in our physical world. Like a physical object, we have examined:

- What does it contain (in terms of data)?

- What can it do (in terms of operations and functions)?
- What can it do (in terms of functions)?

And if it "makes sense" to us, then it is well-designed.

The list data structure we have been working with is an example of an **Object**. The definition of an object allows us to ask the questions above: *what does it contain, and what can it do?* It is an organizational tool for a collection of data and functions that we can relate to, like a physical object. Formally, an object contains the following:

- **Value** that holds the essential data for the object.

- **Attributes** that store additional data for the object.
- **Attributes** that hold subset or additional data for the object.

- Functions called **Methods** that can be used on the object.
- Functions called **Methods** that automatically takes the object as input.

This organizing structure on an object applies to pretty much all Python data types and data structures.

Expand All @@ -138,6 +130,14 @@ Here are some more examples of methods with lists:
| [`chrNum.sort()`](https://docs.python.org/3/tutorial/datastructures.html) | list `chrNum` | Sorts `chrNum` by ascending order. | None (but `chrNum` is modified!) |
| [`chrNum.reverse()`](https://docs.python.org/3/tutorial/datastructures.html) | list `chrNum` | Reverses the order of `chrNum`. | None (but `chrNum` is modified!) |

## Methods vs Functions

**Methods** *have to* take in the object of interest as an input: `chrNum.count(2)` automatically treat `chrNum` as an input. Methods are built for a specific Object type.

**Functions** do not have an implied input: `len(chrNum)` requires specifying a list in the input.

Otherwise, there is no strong distinction between the two.

## Dataframes

A Dataframe is a two-dimensional data structure that stores data like a spreadsheet does.
Expand All @@ -162,11 +162,11 @@ There is a similar function [`pd.read_excel()`](https://pandas.pydata.org/docs/r

Let's investigate the Dataframe as an object:

- What does a Dataframe contain (in terms of data)?
- What does a Dataframe contain (values, attributes)?

- What can a Dataframe do (in terms of operations and functions)?
- What can a Dataframe do (methods)?

### What does a Dataframe contain (in terms of data)?
## What does a Dataframe contain?

We first take a look at the contents:

Expand Down Expand Up @@ -194,6 +194,28 @@ metadata

It looks like there are 1864 rows and 30 columns in this Dataframe, and when we display it it shows some of the data.


``` python
metadata
```

```
## ModelID ... OncotreeLineage
## 0 ACH-000001 ... Ovary/Fallopian Tube
## 1 ACH-000002 ... Myeloid
## 2 ACH-000003 ... Bowel
## 3 ACH-000004 ... Myeloid
## 4 ACH-000005 ... Myeloid
## ... ... ... ...
## 1859 ACH-002968 ... Esophagus/Stomach
## 1860 ACH-002972 ... Esophagus/Stomach
## 1861 ACH-002979 ... Esophagus/Stomach
## 1862 ACH-002981 ... Esophagus/Stomach
## 1863 ACH-003071 ... Lung
##
## [1864 rows x 30 columns]
```

We can look at specific columns by looking at **attributes** via the dot operation. We can also look at the columns via the bracket operation.


Expand Down Expand Up @@ -265,7 +287,7 @@ metadata.shape
## (1864, 30)
```

### What can a Dataframe do (in terms of operations and functions)?
## What can a Dataframe do?

We can use the [`.head()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.head.html) and [`.tail()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.tail.html) methods to look at the first few rows and last few rows of `metadata`, respectively:

Expand Down Expand Up @@ -302,11 +324,11 @@ metadata.tail()

Both of these functions (without input arguments) are considered as **methods**: they are functions that does something with the Dataframe you are using it on. You should think about `metadata.head()` as a function that takes in `metadata` as an input. If we had another Dataframe called `my_data` and you want to use the same function, you will have to say `my_data.head()`.

#### Subsetting Dataframes
## Subsetting Dataframes

Perhaps the most important operation you will can do with Dataframes is subsetting them. There are two ways to do it. The first way is to subset by numerical indicies, exactly like how we did for lists.

You will use the [`iloc`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html) and bracket operations, and you give two slices: one for the row, and one for the column.
You will use the [`iloc`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html) attribute and bracket operations, and you give two slices: one for the row, and one for the column.

Let's start with a small dataframe to see how it works before returning to `metadata`:

Expand All @@ -331,9 +353,9 @@ Here is how the dataframe looks like with the row and column index numbers:

![](images/pandas_subset_0.png)

Subset the second to fourth rows, and the first two columns:
Subset the first fourth rows, and the first two columns:

![](images/pandas_subset_1.png)
![](images/pandas subset_1.png)

Now, back to `metadata` dataframe:

Expand Down
2 changes: 1 addition & 1 deletion docs/no_toc/03-data-wrangling1.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ plt.show()

<img src="resources/images/03-data-wrangling1_files/figure-html/unnamed-chunk-12-3.png" width="672" />

(The `plt.figure()` and `plt.show()` functions are used to render the plots on the website, but you don't need to use it for your exercises - yet. We will discuss this in more detail during our week of data visualization.)
(The `plt.figure()` and `plt.show()` functions are used to render the plots on the website, but you don't need to use it for your exercises. We will discuss this in more detail during our week of data visualization.)

#### Chained function calls

Expand Down
16 changes: 8 additions & 8 deletions docs/no_toc/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
<li class="chapter" data-level="1.4" data-path="intro-to-computing.html"><a href="intro-to-computing.html#google-colab-setup"><i class="fa fa-check"></i><b>1.4</b> Google Colab Setup</a></li>
<li class="chapter" data-level="1.5" data-path="intro-to-computing.html"><a href="intro-to-computing.html#grammar-structure-1-evaluation-of-expressions"><i class="fa fa-check"></i><b>1.5</b> Grammar Structure 1: Evaluation of Expressions</a>
<ul>
<li class="chapter" data-level="1.5.1" data-path="intro-to-computing.html"><a href="intro-to-computing.html#data-types"><i class="fa fa-check"></i><b>1.5.1</b> Data types</a></li>
<li class="chapter" data-level="1.5.2" data-path="intro-to-computing.html"><a href="intro-to-computing.html#function-machine-schema"><i class="fa fa-check"></i><b>1.5.2</b> Function machine schema</a></li>
<li class="chapter" data-level="1.5.1" data-path="intro-to-computing.html"><a href="intro-to-computing.html#function-machine-schema"><i class="fa fa-check"></i><b>1.5.1</b> Function machine schema</a></li>
<li class="chapter" data-level="1.5.2" data-path="intro-to-computing.html"><a href="intro-to-computing.html#data-types"><i class="fa fa-check"></i><b>1.5.2</b> Data types</a></li>
</ul></li>
<li class="chapter" data-level="1.6" data-path="intro-to-computing.html"><a href="intro-to-computing.html#grammar-structure-2-storing-data-types-in-the-variable-environment"><i class="fa fa-check"></i><b>1.6</b> Grammar Structure 2: Storing data types in the Variable Environment</a>
<ul>
Expand All @@ -174,12 +174,12 @@
<li class="chapter" data-level="2.1.2" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#subsetting-multiple-elements-of-lists"><i class="fa fa-check"></i><b>2.1.2</b> Subsetting multiple elements of lists</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#objects-in-python"><i class="fa fa-check"></i><b>2.2</b> Objects in Python</a></li>
<li class="chapter" data-level="2.3" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#dataframes"><i class="fa fa-check"></i><b>2.3</b> Dataframes</a>
<ul>
<li class="chapter" data-level="2.3.1" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#what-does-a-dataframe-contain-in-terms-of-data"><i class="fa fa-check"></i><b>2.3.1</b> What does a Dataframe contain (in terms of data)?</a></li>
<li class="chapter" data-level="2.3.2" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#what-can-a-dataframe-do-in-terms-of-operations-and-functions"><i class="fa fa-check"></i><b>2.3.2</b> What can a Dataframe do (in terms of operations and functions)?</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#exercises-1"><i class="fa fa-check"></i><b>2.4</b> Exercises</a></li>
<li class="chapter" data-level="2.3" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#methods-vs-functions"><i class="fa fa-check"></i><b>2.3</b> Methods vs Functions</a></li>
<li class="chapter" data-level="2.4" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#dataframes"><i class="fa fa-check"></i><b>2.4</b> Dataframes</a></li>
<li class="chapter" data-level="2.5" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#what-does-a-dataframe-contain"><i class="fa fa-check"></i><b>2.5</b> What does a Dataframe contain?</a></li>
<li class="chapter" data-level="2.6" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#what-can-a-dataframe-do"><i class="fa fa-check"></i><b>2.6</b> What can a Dataframe do?</a></li>
<li class="chapter" data-level="2.7" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#subsetting-dataframes"><i class="fa fa-check"></i><b>2.7</b> Subsetting Dataframes</a></li>
<li class="chapter" data-level="2.8" data-path="working-with-data-structures.html"><a href="working-with-data-structures.html#exercises-1"><i class="fa fa-check"></i><b>2.8</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="data-wrangling-part-1.html"><a href="data-wrangling-part-1.html"><i class="fa fa-check"></i><b>3</b> Data Wrangling, Part 1</a>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/no_toc/About.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ These credits are based on our [course contributors table guidelines](https://ww
## collate en_US.UTF-8
## ctype en_US.UTF-8
## tz Etc/UTC
## date 2024-09-10
## date 2024-09-25
## pandoc 3.1.1 @ /usr/local/bin/ (via rmarkdown)
##
## ─ Packages ───────────────────────────────────────────────────────────────────
Expand Down
Loading

0 comments on commit a4ad23b

Please sign in to comment.