diff --git a/docs/no_toc/02-data-structures.md b/docs/no_toc/02-data-structures.md index bd24e0d..f183ba9 100644 --- a/docs/no_toc/02-data-structures.md +++ b/docs/no_toc/02-data-structures.md @@ -124,7 +124,7 @@ Object methods are functions that does something with the object you are using i Here are some more examples of methods with lists: | Function method | What it takes in | What it does | Returns | -|---------------|---------------|---------------------------|---------------| +|------------------------------------------------------------------------------|------------------------------|-----------------------------------------------------------------------|----------------------------------| | [`chrNum.count(x)`](https://docs.python.org/3/tutorial/datastructures.html) | list `chrNum`, data type `x` | Counts the number of instances `x` appears as an element of `chrNum`. | Integer | | [`chrNum.append(x)`](https://docs.python.org/3/tutorial/datastructures.html) | list `chrNum`, data type `x` | Appends `x` to the end of the `chrNum`. | None (but `chrNum` is modified!) | | [`chrNum.sort()`](https://docs.python.org/3/tutorial/datastructures.html) | list `chrNum` | Sorts `chrNum` by ascending order. | None (but `chrNum` is modified!) | @@ -324,7 +324,7 @@ 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. @@ -355,7 +355,7 @@ Here is how the dataframe looks like with the row and column index numbers: Subset the first fourth rows, and the first two columns: -![](images/pandas subset_1.png) +![](images/pandas%20subset_1.png) Now, back to `metadata` dataframe: diff --git a/docs/no_toc/03-data-wrangling1.md b/docs/no_toc/03-data-wrangling1.md index 50ee0c1..cf3e14e 100644 --- a/docs/no_toc/03-data-wrangling1.md +++ b/docs/no_toc/03-data-wrangling1.md @@ -100,7 +100,7 @@ expression.head() ``` | Dataframe | The observation is | Some variables are | Some values are | -|-----------------|-----------------|--------------------|------------------| +|------------|--------------------|-------------------------------|-----------------------------| | metadata | Cell line | ModelID, Age, OncotreeLineage | "ACH-000001", 60, "Myeloid" | | expression | Cell line | KRAS_Exp | 2.4, .3 | | mutation | Cell line | KRAS_Mut | TRUE, FALSE | @@ -117,9 +117,9 @@ Here's a starting prompt: We have been using **explicit subsetting** with numerical indicies, such as "I want to filter for rows 20-50 and select columns 2 and 8". We are now going to switch to **implicit subsetting** in which we describe the subsetting criteria via comparision operators and column names, such as: -*"I want to subset for rows such that the OncotreeLineage is breast cancer and subset for columns Age and Sex."* +*"I want to subset for rows such that the OncotreeLineage is lung cancer and subset for columns Age and Sex."* -Notice that when we subset for rows in an implicit way, we formulate our criteria in terms of the columns.This is because we are guaranteed to have column names in Dataframes, but not row names. +Notice that when we subset for rows in an implicit way, we formulate our criteria in terms of the columns. This is because we are guaranteed to have column names in Dataframes, but not row names. #### Let's convert our implicit subsetting criteria into code! @@ -145,7 +145,7 @@ metadata['OncotreeLineage'] == "Lung" ## Name: OncotreeLineage, Length: 1864, dtype: bool ``` -Then, we will use the [`.loc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html) operation (which is different than [`.iloc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html) operation!) and subsetting brackets to subset rows and columns Age and Sex at the same time: +Then, we will use the [`.loc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html) attribute (which is different than [`.iloc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html) attribute!) and subsetting brackets to subset rows and columns Age and Sex at the same time: ``` python @@ -213,7 +213,7 @@ Now that your Dataframe has be transformed based on your scientific question, yo If we look at the data structure of a Dataframe's column, it is actually not a List, but an object called Series. It has methods can compute summary statistics for us. Let's take a look at a few popular examples: | Function method | What it takes in | What it does | Returns | -|----------------|----------------|------------------------|----------------| +|---------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|-------------------------------------------------------------------------------|---------------| | [`metadata.Age.mean()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.mean.html) | `metadata.Age` as a numeric Series | Computes the mean value of the `Age` column. | Float (NumPy) | | [`metadata['Age'].median()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.median.html) | `metadata['Age']` as a numeric Series | Computes the median value of the `Age` column. | Float (NumPy) | | [`metadata.Age.max()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.max.html) | `metadata.Age` as a numeric Series | Computes the max value of the `Age` column. | Float (NumPy) | @@ -277,7 +277,7 @@ Notice that the output of some of these methods are Float (NumPy). This refers t We will dedicate extensive time later this course to talk about data visualization, but the Dataframe's column, Series, has a method called [`.plot()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.plot.html) that can help us make simple plots for one variable. The `.plot()` method will by default make a line plot, but it is not necessary the plot style we want, so we can give the optional argument `kind` a String value to specify the plot style. We use it for making a histogram or bar plot. | Plot style | Useful for | kind = | Code | -|-------------|-------------|-------------|---------------------------------| +|------------|------------|--------|--------------------------------------------------------------| | Histogram | Numerics | "hist" | `metadata.Age.plot(kind = "hist")` | | Bar plot | Strings | "bar" | `metadata.OncotreeSubtype.value_counts().plot(kind = "bar")` | diff --git a/docs/no_toc/04-data-wrangling2.md b/docs/no_toc/04-data-wrangling2.md index 77cb01c..2e07dbc 100644 --- a/docs/no_toc/04-data-wrangling2.md +++ b/docs/no_toc/04-data-wrangling2.md @@ -164,7 +164,7 @@ To get there, we need to: - **Summarize** each group via a summary statistic performed on a column, such as `Age`. -We first subset the the two columns we need, and then use the methods [`.group_by(x)`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html) and `.mean()`. +We use the methods [`.group_by(x)`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html) and `.mean()`. ``` python @@ -210,7 +210,7 @@ metadata_grouped['Age'].mean() Here's what's going on: -- We use the Dataframe method [`.group_by(x)`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html) and specify the column we want to group by. The output of this method is a Grouped Dataframe object. It still contains all the information of the `metadata` Dataframe, but it makes a note that it's been grouped. +- We use the Dataframe method [`.group_by(x)`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html) and specify the column we want to group by. The output of this method is a **Grouped Dataframe object**. It still contains all the information of the `metadata` Dataframe, but it makes a note that it's been grouped. - We subset to the column `Age`. The grouping information still persists (This is a Grouped Series object). diff --git a/docs/no_toc/05-data-visualization.md b/docs/no_toc/05-data-visualization.md index 71d4a68..774445e 100644 --- a/docs/no_toc/05-data-visualization.md +++ b/docs/no_toc/05-data-visualization.md @@ -30,7 +30,7 @@ Categorical (between 1 categorical and 1 continuous variable) - Violin plots -[![Image source: Seaborn's overview of plotting functions](https://seaborn.pydata.org/_images/function_overview_8_0.png)](https://seaborn.pydata.org/tutorial/function_overview.html) +[![Image source: Seaborn\'s overview of plotting functions](https://seaborn.pydata.org/_images/function_overview_8_0.png)](https://seaborn.pydata.org/tutorial/function_overview.html) Why do we focus on these common plots? Our eyes are better at distinguishing certain visual features more than others. All of these plots are focused on their position to depict data, which gives us the most effective visual scale. @@ -221,6 +221,10 @@ plot = sns.displot(data=metadata, x="Age", hue="Sex", multiple="dodge", palette= +## Other resources + +We recommend checking out the workshop [Better Plots](https://hutchdatascience.org/better_plots/), which showcase examples of how to clean up your plots for clearer communication. + ## Exercises -Exercise for week 5 can be found [here](https://colab.research.google.com/drive/1kT3zzq2rrhL1vHl01IdW5L1V7v0iK0wY?usp=sharing). +Exercise for week 5 can be found [here](https://colab.research.google.com/drive/17iwr8NwLLrmzRj4a6zRZucETXpPkmDNR?usp=sharing). diff --git a/docs/no_toc/404.html b/docs/no_toc/404.html index ac6d572..aeb75df 100644 --- a/docs/no_toc/404.html +++ b/docs/no_toc/404.html @@ -206,7 +206,8 @@
Bar plots
Violin plots
Why do we focus on these common plots? Our eyes are better at distinguishing certain visual features more than others. All of these plots are focused on their position to depict data, which gives us the most effective visual scale.
Let’s load in our genomics datasets and start making some plots from them.
@@ -363,9 +364,13 @@## <string>:1: UserWarning: The palette list has more values (6) than needed (3), which may not be intended.
-Exercise for week 5 can be found here.
+We recommend checking out the workshop Better Plots, which showcase examples of how to clean up your plots for clearer communication.
+Exercise for week 5 can be found here.