Skip to content
Snippets Groups Projects
Commit 9dcd4eea authored by Yuxuan Mei's avatar Yuxuan Mei
Browse files

add fri materials

parent 52036f60
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:8a4f78b6-0e92-4965-88c3-23110651b371 tags:
# Spreadsheets
By the end of this lesson, students will be able to:
- Design spreadsheet data models that enable reproducible data analysis.
- Convert a pivot table operation to `pandas` `groupby` and vice versa.
- Write spreadsheet formulas that apply a function over many cells.
For this lesson, we'll spend most of our time in the preceding notebook on [groupby-and-indexing.ipynb](groupby-and-indexing.ipynb).
Later, we'll download the `earthquakes.csv` file and use it to create a spreadsheet. In lecture, we will visit [sheets.new](https://sheets.new) to create a new Google Sheet.
%% Cell type:code id:494a3641 tags:
``` python
import pandas as pd
import seaborn as sns
sns.set_theme()
```
%% Cell type:markdown id:37a0cdc1 tags:
### What is pivot table?
Let's first revisit the life expectancy dataset and use this as an example of showing what it is in pandas.
%% Cell type:code id:a344f81a tags:
``` python
life_expectancy = sns.load_dataset("healthexp", index_col=["Year", "Country"])
life_expectancy
```
%% Cell type:markdown id:b36c314e tags:
Let's try pivoting the table about the "Country" column. We can read the documentation of `pivot_table` [here](https://pandas.pydata.org/docs/reference/api/pandas.pivot_table.html).
%% Cell type:code id:672500b8 tags:
``` python
pivoted_table = life_expectancy.pivot_table(index="Year", columns="Country", values="Life_Expectancy")
pivoted_table.head()
```
%% Cell type:code id:1d994006 tags:
``` python
life_expectancy.columns, pivoted_table.columns
```
%% Cell type:code id:1eafc202 tags:
``` python
sns.relplot(pivoted_table, kind="line")
# pretty much the same as
# sns.relplot(life_expectancy, x="Year", y="Life_Expectancy", hue="Country", kind="line")
```
%% Cell type:markdown id:d382e27c tags:
### Check the pandas version of earthquakes pivot table
%% Cell type:code id:a32efdf6 tags:
``` python
earthquakes = pd.read_csv("earthquakes.csv")
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment