{
"cells": [
{
"cell_type": "markdown",
"id": "d3713984",
"metadata": {},
"source": [
"# Class 5: Accessing Data, continued\n",
"\n",
"Today's agenda:\n",
"\n",
"- warm up/ review\n",
"- announcements\n",
"- working with dataframes\n",
"- the power of functions as objects\n",
"- (maybe) exploratory data analysis"
]
},
{
"cell_type": "markdown",
"id": "b8034373",
"metadata": {},
"source": [
"```{admonition} Try it out -->\n",
"Read the tables off of the [syllabus course map]('https://rhodyprog4ds.github.io/BrownFall20/syllabus/course_map.html) page with `read_html` and make a list of the shapes of all of the tables on the page. Save the output to a variable and paste the *value* of that variable as your answer to the question.\n",
"\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7bda5359",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(14, 3), (15, 5), (15, 15), (15, 6)]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"[df.shape for df in pd.read_html('https://rhodyprog4ds.github.io/BrownFall20/syllabus/course_map.html')]"
]
},
{
"cell_type": "markdown",
"id": "4942501a",
"metadata": {},
"source": [
"## Announcements\n",
"\n",
"- annotated notes are up\n",
"- beginning portfolio prompts and instructions are up\n",
"- Assignment due Sunday,\n",
"- office hours will remain Fridays\n",
"- TA office hours posted.\n",
"\n",
"## More Pandas\n",
"\n",
"We'll go back to the SAFI dataset from Wednesday."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ec38b0f3",
"metadata": {},
"outputs": [],
"source": [
"safi_df = pd.read_csv('https://raw.githubusercontent.com/brownsarahm/python-socialsci-files/master/data/SAFI_clean.csv')"
]
},
{
"cell_type": "markdown",
"id": "38634c9f",
"metadata": {},
"source": [
"We downloaded the data into memory, but we can also write it to disk."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6d0ae13a",
"metadata": {},
"outputs": [],
"source": [
"safi_df.to_csv('safi_clean.csv')"
]
},
{
"cell_type": "markdown",
"id": "bd86bedb",
"metadata": {},
"source": [
"It will go to the same folder as the notebook, but we can also use a relative path. If we make a `data` folder in the folder where we've saved the notebook, we can write the file there instead.\n",
"\n",
"````{margin}\n",
"```{tip}\n",
"In class we used the Jupyter GUI to create a new folder. You could also use your computer's default file management tool (Windows Explorer, Mac Finder, etc). Here, since the notebooks have to run completely automatically for this website, we use a ipython [`bash` magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#cellmagic-bash) cell to make the folder. Jupyter notebooks use an ipython kernel.\n",
"```\n",
"````"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "2faf9878",
"metadata": {},
"outputs": [],
"source": [
"safi_df.to_csv('data/safi_clean.csv')"
]
},
{
"cell_type": "markdown",
"id": "6ef2b9f7",
"metadata": {},
"source": [
"Now we can read it in using the same path"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "954d5480",
"metadata": {},
"outputs": [],
"source": [
"safi_df2= pd.read_csv('data/safi_clean.csv')"
]
},
{
"cell_type": "markdown",
"id": "47e666ee",
"metadata": {},
"source": [
"Note that now it has an extra column"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8d1ce949",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
" key_ID village interview_date no_membrs years_liv \\\n",
"0 1 God 2016-11-17T00:00:00Z 3 4 \n",
"1 1 God 2016-11-17T00:00:00Z 7 9 \n",
"\n",
" respondent_wall_type rooms memb_assoc affect_conflicts liv_count \\\n",
"0 muddaub 1 NaN NaN 1 \n",
"1 muddaub 1 yes once 3 \n",
"\n",
" items_owned no_meals \\\n",
"0 bicycle;television;solar_panel;table 2 \n",
"1 cow_cart;bicycle;radio;cow_plough;solar_panel;... 2 \n",
"\n",
" months_lack_food instanceID \n",
"0 Jan uuid:ec241f2c-0609-46ed-b5e8-fe575f6cefef \n",
"1 Jan;Sept;Oct;Nov;Dec uuid:099de9c9-3e5e-427b-8452-26250e840d6e "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"safi_df.head(2)"
]
},
{
"cell_type": "markdown",
"id": "f4000b7b",
"metadata": {},
"source": [
"We can prevent this by writing it out with the `index` parameter set to `False`\n",
"````{margin}\n",
"```{tip}\n",
"False must be with a capital letter to be a boolean variable in python, as with True. You'll know if you did it right in your jupyter notebook, if the word terms bold and green.\n",
"```\n",
"````"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a29263d1",
"metadata": {},
"outputs": [],
"source": [
"safi_df.to_csv('data/safi_clean.csv',index=False)"
]
},
{
"cell_type": "markdown",
"id": "58abe62c",
"metadata": {},
"source": [
"Now when we read it in, there's no extra column."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "e0f9c961",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
" village no_membrs years_liv\n",
"0 God 3 4\n",
"1 God 7 9"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"columns_of_interest = ['village','no_membrs','years_liv']\n",
"safi_df[columns_of_interest].head(2)"
]
},
{
"cell_type": "markdown",
"id": "9feb80f5",
"metadata": {},
"source": [
"## Functions are objects"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "a8004d6a",
"metadata": {},
"outputs": [],
"source": [
"syllabus_df_list = pd.read_html('https://rhodyprog4ds.github.io/BrownFall20/syllabus/course_map.html')"
]
},
{
"cell_type": "markdown",
"id": "d56be257",
"metadata": {},
"source": [
"And we can put them in a dictionary. `lambda` functions are special functions defined in a single line."
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "de4d20ee",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'hello sarah'"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"greetingl = lambda name: 'hello ' + name\n",
"greetingl('sarah')"
]
},
{
"cell_type": "markdown",
"id": "8757fe8d",
"metadata": {},
"source": [
"is the same as"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "3b53765f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'hello sarah'"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def greetingf(name):\n",
" return 'hello ' + name\n",
"greetingf('sarah')"
]
},
{
"cell_type": "markdown",
"id": "93a1173f",
"metadata": {},
"source": [
"So, we can define a function in a dictionary like this:\n",
"````{margin}\n",
"```{tip}\n",
"this is how to do the equivalent of a switch or case in other languages in python\n",
"```\n",
"````"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "d473151b",
"metadata": {},
"outputs": [],
"source": [
"view_rows = {0: lambda df: print(df.head()),\n",
" 1: lambda df: print(df.tail())}"
]
},
{
"cell_type": "markdown",
"id": "1083a84e",
"metadata": {},
"source": [
"The `len` function works on all iterables"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "b6622e45",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Unnamed: 0_level_0 topics \\\n",
" week Unnamed: 1_level_1 \n",
"0 1 [admin, python review] \n",
"1 2 Loading data, Python review \n",
"2 3 Exploratory Data Analysis \n",
"3 4 Data Cleaning \n",
"4 5 Databases, Merging DataFrames \n",
"\n",
" skills \n",
" Unnamed: 2_level_1 \n",
"0 process \n",
"1 [access, prepare, summarize] \n",
"2 [summarize, visualize] \n",
"3 [prepare, summarize, visualize] \n",
"4 [access, construct, summarize] \n",
" Unnamed: 0_level_0 skill \\\n",
" keyword Unnamed: 1_level_1 \n",
"10 evaluate Evaluate model performance \n",
"11 optimize Optimize model parameters \n",
"12 compare compare models \n",
"13 unstructured model unstructured data \n",
"14 workflow use industry standard data science tools and w... \n",
"\n",
" Level 1 \\\n",
" Unnamed: 2_level_1 \n",
"10 Explain basic performance metrics for differen... \n",
"11 Identify when model parameters need to be opti... \n",
"12 Qualitatively compare model classes \n",
"13 Identify options for representing text data an... \n",
"14 Solve well strucutred problems with a single t... \n",
"\n",
" Level 2 \\\n",
" Unnamed: 3_level_1 \n",
"10 Apply basic model evaluation metrics to a held... \n",
"11 Manually optimize basic model parameters such ... \n",
"12 Compare model classes in specific terms and fi... \n",
"13 Apply at least one representation to transform... \n",
"14 Solve semi-strucutred, completely specified pr... \n",
"\n",
" Level 3 \n",
" Unnamed: 4_level_1 \n",
"10 Evaluate a model with multiple metrics and cro... \n",
"11 Select optimal parameters based of mutiple qua... \n",
"12 Evaluate tradeoffs between different model com... \n",
"13 apply multiple representations and compare and... \n",
"14 Scope, choose an appropriate tool pipeline and... \n",
" Unnamed: 0_level_0 A1 A2 \\\n",
" keyword Unnamed: 1_level_1 Unnamed: 2_level_1 \n",
"10 evaluate 0 0 \n",
"11 optimize 0 0 \n",
"12 compare 0 0 \n",
"13 unstructured 0 0 \n",
"14 workflow 0 0 \n",
"\n",
" A3 A4 A5 \\\n",
" Unnamed: 3_level_1 Unnamed: 4_level_1 Unnamed: 5_level_1 \n",
"10 0 0 0 \n",
"11 0 0 0 \n",
"12 0 0 0 \n",
"13 0 0 0 \n",
"14 0 0 0 \n",
"\n",
" A6 A7 A8 \\\n",
" Unnamed: 6_level_1 Unnamed: 7_level_1 Unnamed: 8_level_1 \n",
"10 0 0 0 \n",
"11 0 0 0 \n",
"12 0 0 0 \n",
"13 0 0 0 \n",
"14 0 0 0 \n",
"\n",
" A9 A10 A11 \\\n",
" Unnamed: 9_level_1 Unnamed: 10_level_1 Unnamed: 11_level_1 \n",
"10 0 1 1 \n",
"11 0 1 1 \n",
"12 0 0 1 \n",
"13 0 0 0 \n",
"14 0 1 1 \n",
"\n",
" A12 A13 # Assignments \n",
" Unnamed: 12_level_1 Unnamed: 13_level_1 Unnamed: 14_level_1 \n",
"10 0 0 2 \n",
"11 0 0 2 \n",
"12 0 1 2 \n",
"13 1 1 2 \n",
"14 1 1 4 \n",
" Unnamed: 0_level_0 Level 3 \\\n",
" keyword Unnamed: 1_level_1 \n",
"10 evaluate Evaluate a model with multiple metrics and cro... \n",
"11 optimize Select optimal parameters based of mutiple qua... \n",
"12 compare Evaluate tradeoffs between different model com... \n",
"13 unstructured apply multiple representations and compare and... \n",
"14 workflow Scope, choose an appropriate tool pipeline and... \n",
"\n",
" P1 P2 P3 P4 \n",
" Unnamed: 2_level_1 Unnamed: 3_level_1 Unnamed: 4_level_1 Unnamed: 5_level_1 \n",
"10 0 1 1 0 \n",
"11 0 0 1 1 \n",
"12 0 0 1 1 \n",
"13 0 0 1 1 \n",
"14 0 0 1 1 \n"
]
}
],
"source": [
"for df in syllabus_df_list:\n",
" num_row = len(df)\n",
" view_rows[num_row%2](df)\n"
]
},
{
"cell_type": "markdown",
"id": "ff34d7dc",
"metadata": {},
"source": [
"## The beginning of Exploratory Data Analysis\n",
"\n",
"Pandas will give us descriptive statistics"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "f4083fc4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
key_ID
\n",
"
no_membrs
\n",
"
years_liv
\n",
"
rooms
\n",
"
liv_count
\n",
"
no_meals
\n",
"
\n",
" \n",
" \n",
"
\n",
"
count
\n",
"
131.000000
\n",
"
131.00000
\n",
"
131.000000
\n",
"
131.000000
\n",
"
131.000000
\n",
"
131.000000
\n",
"
\n",
"
\n",
"
mean
\n",
"
85.473282
\n",
"
7.19084
\n",
"
23.053435
\n",
"
1.740458
\n",
"
2.366412
\n",
"
2.603053
\n",
"
\n",
"
\n",
"
std
\n",
"
63.151628
\n",
"
3.17227
\n",
"
16.913041
\n",
"
1.092547
\n",
"
1.082775
\n",
"
0.491143
\n",
"
\n",
"
\n",
"
min
\n",
"
1.000000
\n",
"
2.00000
\n",
"
1.000000
\n",
"
1.000000
\n",
"
1.000000
\n",
"
2.000000
\n",
"
\n",
"
\n",
"
25%
\n",
"
32.500000
\n",
"
5.00000
\n",
"
12.000000
\n",
"
1.000000
\n",
"
1.000000
\n",
"
2.000000
\n",
"
\n",
"
\n",
"
50%
\n",
"
66.000000
\n",
"
7.00000
\n",
"
20.000000
\n",
"
1.000000
\n",
"
2.000000
\n",
"
3.000000
\n",
"
\n",
"
\n",
"
75%
\n",
"
138.000000
\n",
"
9.00000
\n",
"
27.500000
\n",
"
2.000000
\n",
"
3.000000
\n",
"
3.000000
\n",
"
\n",
"
\n",
"
max
\n",
"
202.000000
\n",
"
19.00000
\n",
"
96.000000
\n",
"
8.000000
\n",
"
5.000000
\n",
"
3.000000
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" key_ID no_membrs years_liv rooms liv_count no_meals\n",
"count 131.000000 131.00000 131.000000 131.000000 131.000000 131.000000\n",
"mean 85.473282 7.19084 23.053435 1.740458 2.366412 2.603053\n",
"std 63.151628 3.17227 16.913041 1.092547 1.082775 0.491143\n",
"min 1.000000 2.00000 1.000000 1.000000 1.000000 2.000000\n",
"25% 32.500000 5.00000 12.000000 1.000000 1.000000 2.000000\n",
"50% 66.000000 7.00000 20.000000 1.000000 2.000000 3.000000\n",
"75% 138.000000 9.00000 27.500000 2.000000 3.000000 3.000000\n",
"max 202.000000 19.00000 96.000000 8.000000 5.000000 3.000000"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"safi_df.describe()"
]
},
{
"cell_type": "markdown",
"id": "8ed8bd4d",
"metadata": {},
"source": [
"The statistics of the `key_ID` column don't make a lot of sense. We can avoid that by making it the index"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "26f87216",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
key_ID
\n",
"
village
\n",
"
interview_date
\n",
"
no_membrs
\n",
"
years_liv
\n",
"
respondent_wall_type
\n",
"
rooms
\n",
"
memb_assoc
\n",
"
affect_conflicts
\n",
"
liv_count
\n",
"
items_owned
\n",
"
no_meals
\n",
"
months_lack_food
\n",
"
instanceID
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
1
\n",
"
God
\n",
"
2016-11-17T00:00:00Z
\n",
"
3
\n",
"
4
\n",
"
muddaub
\n",
"
1
\n",
"
NaN
\n",
"
NaN
\n",
"
1
\n",
"
bicycle;television;solar_panel;table
\n",
"
2
\n",
"
Jan
\n",
"
uuid:ec241f2c-0609-46ed-b5e8-fe575f6cefef
\n",
"
\n",
"
\n",
"
1
\n",
"
1
\n",
"
God
\n",
"
2016-11-17T00:00:00Z
\n",
"
7
\n",
"
9
\n",
"
muddaub
\n",
"
1
\n",
"
yes
\n",
"
once
\n",
"
3
\n",
"
cow_cart;bicycle;radio;cow_plough;solar_panel;...
\n",
"
2
\n",
"
Jan;Sept;Oct;Nov;Dec
\n",
"
uuid:099de9c9-3e5e-427b-8452-26250e840d6e
\n",
"
\n",
"
\n",
"
2
\n",
"
3
\n",
"
God
\n",
"
2016-11-17T00:00:00Z
\n",
"
10
\n",
"
15
\n",
"
burntbricks
\n",
"
1
\n",
"
NaN
\n",
"
NaN
\n",
"
1
\n",
"
solar_torch
\n",
"
2
\n",
"
Jan;Feb;Mar;Oct;Nov;Dec
\n",
"
uuid:193d7daf-9582-409b-bf09-027dd36f9007
\n",
"
\n",
"
\n",
"
3
\n",
"
4
\n",
"
God
\n",
"
2016-11-17T00:00:00Z
\n",
"
7
\n",
"
6
\n",
"
burntbricks
\n",
"
1
\n",
"
NaN
\n",
"
NaN
\n",
"
2
\n",
"
bicycle;radio;cow_plough;solar_panel;mobile_phone
\n",
"
2
\n",
"
Sept;Oct;Nov;Dec
\n",
"
uuid:148d1105-778a-4755-aa71-281eadd4a973
\n",
"
\n",
"
\n",
"
4
\n",
"
5
\n",
"
God
\n",
"
2016-11-17T00:00:00Z
\n",
"
7
\n",
"
40
\n",
"
burntbricks
\n",
"
1
\n",
"
NaN
\n",
"
NaN
\n",
"
4
\n",
"
motorcyle;radio;cow_plough;mobile_phone
\n",
"
2
\n",
"
Aug;Sept;Oct;Nov
\n",
"
uuid:2c867811-9696-4966-9866-f35c3e97d02d
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" key_ID village interview_date no_membrs years_liv \\\n",
"0 1 God 2016-11-17T00:00:00Z 3 4 \n",
"1 1 God 2016-11-17T00:00:00Z 7 9 \n",
"2 3 God 2016-11-17T00:00:00Z 10 15 \n",
"3 4 God 2016-11-17T00:00:00Z 7 6 \n",
"4 5 God 2016-11-17T00:00:00Z 7 40 \n",
"\n",
" respondent_wall_type rooms memb_assoc affect_conflicts liv_count \\\n",
"0 muddaub 1 NaN NaN 1 \n",
"1 muddaub 1 yes once 3 \n",
"2 burntbricks 1 NaN NaN 1 \n",
"3 burntbricks 1 NaN NaN 2 \n",
"4 burntbricks 1 NaN NaN 4 \n",
"\n",
" items_owned no_meals \\\n",
"0 bicycle;television;solar_panel;table 2 \n",
"1 cow_cart;bicycle;radio;cow_plough;solar_panel;... 2 \n",
"2 solar_torch 2 \n",
"3 bicycle;radio;cow_plough;solar_panel;mobile_phone 2 \n",
"4 motorcyle;radio;cow_plough;mobile_phone 2 \n",
"\n",
" months_lack_food instanceID \n",
"0 Jan uuid:ec241f2c-0609-46ed-b5e8-fe575f6cefef \n",
"1 Jan;Sept;Oct;Nov;Dec uuid:099de9c9-3e5e-427b-8452-26250e840d6e \n",
"2 Jan;Feb;Mar;Oct;Nov;Dec uuid:193d7daf-9582-409b-bf09-027dd36f9007 \n",
"3 Sept;Oct;Nov;Dec uuid:148d1105-778a-4755-aa71-281eadd4a973 \n",
"4 Aug;Sept;Oct;Nov uuid:2c867811-9696-4966-9866-f35c3e97d02d "
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"safi_df.head()"
]
},
{
"cell_type": "markdown",
"id": "11bdf830",
"metadata": {},
"source": [
"the `inplace` parameter of a `pandas` functions applies the operation to the DataFrame in memory, but then the function returns nothing, but if we display after that, we see that now the `key_ID` column is now the index."
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "2dccb6cd",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
village
\n",
"
interview_date
\n",
"
no_membrs
\n",
"
years_liv
\n",
"
respondent_wall_type
\n",
"
rooms
\n",
"
memb_assoc
\n",
"
affect_conflicts
\n",
"
liv_count
\n",
"
items_owned
\n",
"
no_meals
\n",
"
months_lack_food
\n",
"
instanceID
\n",
"
\n",
"
\n",
"
key_ID
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
" \n",
" \n",
"
\n",
"
1
\n",
"
God
\n",
"
2016-11-17T00:00:00Z
\n",
"
3
\n",
"
4
\n",
"
muddaub
\n",
"
1
\n",
"
NaN
\n",
"
NaN
\n",
"
1
\n",
"
bicycle;television;solar_panel;table
\n",
"
2
\n",
"
Jan
\n",
"
uuid:ec241f2c-0609-46ed-b5e8-fe575f6cefef
\n",
"
\n",
"
\n",
"
1
\n",
"
God
\n",
"
2016-11-17T00:00:00Z
\n",
"
7
\n",
"
9
\n",
"
muddaub
\n",
"
1
\n",
"
yes
\n",
"
once
\n",
"
3
\n",
"
cow_cart;bicycle;radio;cow_plough;solar_panel;...
\n",
"
2
\n",
"
Jan;Sept;Oct;Nov;Dec
\n",
"
uuid:099de9c9-3e5e-427b-8452-26250e840d6e
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" village interview_date no_membrs years_liv \\\n",
"key_ID \n",
"1 God 2016-11-17T00:00:00Z 3 4 \n",
"1 God 2016-11-17T00:00:00Z 7 9 \n",
"\n",
" respondent_wall_type rooms memb_assoc affect_conflicts liv_count \\\n",
"key_ID \n",
"1 muddaub 1 NaN NaN 1 \n",
"1 muddaub 1 yes once 3 \n",
"\n",
" items_owned no_meals \\\n",
"key_ID \n",
"1 bicycle;television;solar_panel;table 2 \n",
"1 cow_cart;bicycle;radio;cow_plough;solar_panel;... 2 \n",
"\n",
" months_lack_food instanceID \n",
"key_ID \n",
"1 Jan uuid:ec241f2c-0609-46ed-b5e8-fe575f6cefef \n",
"1 Jan;Sept;Oct;Nov;Dec uuid:099de9c9-3e5e-427b-8452-26250e840d6e "
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"safi_df.set_index('key_ID',inplace=True)\n",
"safi_df.head(2)"
]
},
{
"cell_type": "markdown",
"id": "6a01ba91",
"metadata": {},
"source": [
"and if we describe again, we see it doesn't compute on that column"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "e86faa32",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
no_membrs
\n",
"
years_liv
\n",
"
rooms
\n",
"
liv_count
\n",
"
no_meals
\n",
"
\n",
" \n",
" \n",
"
\n",
"
count
\n",
"
131.00000
\n",
"
131.000000
\n",
"
131.000000
\n",
"
131.000000
\n",
"
131.000000
\n",
"
\n",
"
\n",
"
mean
\n",
"
7.19084
\n",
"
23.053435
\n",
"
1.740458
\n",
"
2.366412
\n",
"
2.603053
\n",
"
\n",
"
\n",
"
std
\n",
"
3.17227
\n",
"
16.913041
\n",
"
1.092547
\n",
"
1.082775
\n",
"
0.491143
\n",
"
\n",
"
\n",
"
min
\n",
"
2.00000
\n",
"
1.000000
\n",
"
1.000000
\n",
"
1.000000
\n",
"
2.000000
\n",
"
\n",
"
\n",
"
25%
\n",
"
5.00000
\n",
"
12.000000
\n",
"
1.000000
\n",
"
1.000000
\n",
"
2.000000
\n",
"
\n",
"
\n",
"
50%
\n",
"
7.00000
\n",
"
20.000000
\n",
"
1.000000
\n",
"
2.000000
\n",
"
3.000000
\n",
"
\n",
"
\n",
"
75%
\n",
"
9.00000
\n",
"
27.500000
\n",
"
2.000000
\n",
"
3.000000
\n",
"
3.000000
\n",
"
\n",
"
\n",
"
max
\n",
"
19.00000
\n",
"
96.000000
\n",
"
8.000000
\n",
"
5.000000
\n",
"
3.000000
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" no_membrs years_liv rooms liv_count no_meals\n",
"count 131.00000 131.000000 131.000000 131.000000 131.000000\n",
"mean 7.19084 23.053435 1.740458 2.366412 2.603053\n",
"std 3.17227 16.913041 1.092547 1.082775 0.491143\n",
"min 2.00000 1.000000 1.000000 1.000000 2.000000\n",
"25% 5.00000 12.000000 1.000000 1.000000 2.000000\n",
"50% 7.00000 20.000000 1.000000 2.000000 3.000000\n",
"75% 9.00000 27.500000 2.000000 3.000000 3.000000\n",
"max 19.00000 96.000000 8.000000 5.000000 3.000000"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"safi_df.describe()"
]
},
{
"cell_type": "markdown",
"id": "6797a49d",
"metadata": {},
"source": [
"We can also call any of those on one column or one statistic."
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "bcd328f9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.7404580152671756"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"safi_df['rooms'].mean()"
]
},
{
"cell_type": "markdown",
"id": "58d3c93f",
"metadata": {},
"source": [
"Pandas also has some built in plotting functions."
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "7affa4a3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEHCAYAAACk6V2yAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAcOElEQVR4nO3df3Ac5Z3n8fd3kJAV22Ah64zXgrVZO1QIKA434fhlF4HFIVnWcOskm9SyhOQoNlXZXMLVHmaXFOSo5PbWeweX5HIbHLIJhFw2GwT2hvzAhEAIy8+xYwtjh1jBBMuHhazIYHGykJnv/TFtMxIz8rTVPT8efV5VU555pvvpbz9ufdTq6ek2d0dERMKTqXUBIi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f0iPp42MxuNbNc1Nd7zOye6CYfXyia7gozeyq6ycNtZnZM1D5shZtxPGtmPzWzs6I+nzezlUWLOilq32FmNxXV/5yZ3Unh6+4nmdm3zGxrdEOJa1MaOplGFPDSyJYAX3X3dwL7gFXAncBqd++i8FX5m47Qx+vungW+RuG6NJ8CTgeuMrN2M3sH8KfAee6+FHgD+LNo3pnAz6Ll7we+AFxM4dorNxct46yoti7gQ2aWLar/f0fzzwUWuPvp7n4G8M2jGA+RcZpqXYDIFOx0983R840ULk87x91/HrXdQelLGRc7dHGrZ4BnPbqIm5k9T+FKh+cD/xZ4Orp2WitvXoHydeAnRfOPuvuYmT0DLCxaxgPuPhj1e0/U5zrgt164gQsU7hp1ipl9BfghsKGC9ReZlAJeGtlo0fM3gDlT6CM/ob88hZ8PA+5w978uMe+Yv3kxp8Pzu3s+uvTsIRMv+HTo9WuHG9yHzOxdFO4m9UkKdxX6RPzVEXmTDtFISF4BhsxsWfT6z4GfTzJ9JR4EPmhm/wYO37T792P2cXE0XyuFWwT+68QJomvlZ9y9G/gchXuGikyJ9uAlNB8DvmZmb6Nw2OPjU+nM3beZ2eco3KYtQ+ESs58C4tyD9ikKN6HpBO5y95wVbilZbAHwzaKzaUr9xSASiy4XLCISKB2iEREJlA7RSPDM7KvAeROav+TuOhVRgqZDNCIigdIhGhGRQCngRUQCpYAXEQmUAl5EJFD/H2Xm4PUXN6ddAAAAAElFTkSuQmCC\n",
"text/plain": [
""
]
},
"metadata": {
"filenames": {
"image/png": "/home/runner/work/BrownFall20/BrownFall20/_build/jupyter_execute/notes/2020-09-18_57_1.png"
},
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"safi_df.plot.scatter('no_membrs','rooms')"
]
},
{
"cell_type": "markdown",
"id": "b9f5e24c",
"metadata": {},
"source": [
"## After Class Questions\n",
"\n",
"````{dropdown} How can we clean data? what other topics will we cover in this class?\n",
"\n",
"Great Question! We'll get to data cleaning soon. See the [Schedule](schedule).\n",
"````\n",
"\n",
"````{dropdown} How does the syntax on the question from prismia today work?\n",
"\n",
"The question was:\n",
"\n",
"> Read the tables off of the [syllabus course map]('https://rhodyprog4ds.github.io/BrownFall20/syllabus/course_map.html) page with `read_html` and make a list of the shapes of all of the tables on the page. Save the output to a variable and paste the *value* of that variable as your answer to the question.\n",
"\n",
"And the solution was:\n",
"```{code-cell} ipython3\n",
"import pandas as pd\n",
"[df.shape for df in pd.read_html('https://rhodyprog4ds.github.io/BrownFall20/syllabus/course_map.html')]\n",
"```\n",
"\n",
"This uses something called a [list comprehension](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions), they are a way to make lists, that look a lot like putting a for loop in a list. There are two ways to use them under the hood, as in the linked documentation, the one above is considered more pythonic, because it is more concise.\n",
"\n",
"The `[]` define a list, we can do that with anything, for example my zoom meetings today were:\n",
"\n",
"\n",
"```{code-cell} ipython3\n",
"todays_meetings = ['writing QEM','CSC310', 'office hours']\n",
"todays_meetings\n",
"```\n",
"Note that the last line is there to display what happened, but it would work without.\n",
"\n",
"We could get the same output using [`append`](https://docs.python.org/2/tutorial/datastructures.html#more-on-lists) and a regular `for` loop. That syntax would look like:\n",
"\n",
"```{code-cell} ipython3\n",
"shape_list = []\n",
"\n",
"for df in pd.read_html('https://rhodyprog4ds.github.io/BrownFall20/syllabus/course_map.html'):\n",
" shape_list.append(df.shape)\n",
"\n",
"shape_list\n",
"```\n",
"\n",
"````\n",
"\n",
"\n",
"````{dropdown} Where I can go to find a list of all the syntax.\n",
"\n",
"A *list* of all the syntax might be hard to find, but the [course textbook](https://jakevdp.github.io/PythonDataScienceHandbook/) is free online with a lot of reference material in it.\n",
"\n",
"A lot of what we did today is in [Data Indexing and Selection](https://jakevdp.github.io/PythonDataScienceHandbook/03.02-data-indexing-and-selection.html)\n",
"\n",
"Also, the class notes are listed after each class on this website.\n",
"\n",
"Also, you can get help from within a notebook and the [pandas User guide](https://pandas.pydata.org/docs/user_guide/index.html) has full details.\n",
"\n",
"\n",
"````\n",
"\n",
"## More Practice\n",
"\n",
"These additional questions are for if you want more practice with things we've done this week, before class next week.\n",
"\n",
"\n",
"````{dropdown} Which of the following is a dictionary?\n",
"```{code-cell} ipython3\n",
"opt1 = [char for char in 'abcde']\n",
"opt2 = {char:i for i, char in enumerate('abcde')}\n",
"opt3 = ('a','b','c','d','e')\n",
"opt4 = 'a b c d e'.split(' ')\n",
"```\n",
"\n",
"Check using the `type` function. We can go further and build a list of them to display the one that's a dictionary.\n",
"\n",
"First, we can look at them\n",
"```{code-cell} ipython3\n",
"options = [opt1, opt2, opt3, opt4]\n",
"\n",
"for op in options:\n",
" print(op)\n",
"```\n",
"\n",
"Then we can check the types and find the dictionary\n",
"```{code-cell} ipython3\n",
"[op for op in options if type(op)==dict]\n",
"```\n",
"\n",
"````\n",
"\n",
"\n",
"````{dropdown} What type is the shape of a pandas DataFrame?\n",
"\n",
"We can find that by using the `type` function:\n",
"```{code-cell} ipython3\n",
"type(safi_df.shape)\n",
"```\n",
"\n",
"`tuple` is another iterable type, so we can index them\n",
"\n",
"```{code-cell} ipython3\n",
"safi_shape = safi_df.shape\n",
"safi_shape[0]\n",
"```\n",
"\n",
"Also, in python, we can assign to multiple values when it returns a tuple. We saw this before, when we used the `items()` method on a dictionary.\n",
"\n",
"```{code-cell} ipython3\n",
"ex_dict = {char:i for i, char in enumerate('abcde')}\n",
"\n",
"for k,v in ex_dict.items():\n",
" print(k, ' is the ',v,'th letter')\n",
"\n",
"```\n",
"\n",
"we can see that with the type function\n",
"```{code-cell} ipython3\n",
"[type(d) for ex_dict in d1.items()]\n",
"```\n",
"\n",
"So, with the shape property we could also return it to two values\n",
"\n",
"```{code-cell} ipython3\n",
"n_rows, n_cols = safi_df.shape\n",
"print('there are ',n_rows, ' rows and ', n_cols, ' columns')\n",
"```\n",
"\n",
"````\n",
"\n",
"````{dropdown} What does indexing with -1 do?\n",
"\n",
"It returns the last value, here's an example, using the `todays_meetings` variable defined above.\n",
"\n",
"```{code-cell} ipython3\n",
"todays_meetings\n",
"```\n",
"\n",
"\n",
"```{code-cell} ipython3\n",
"todays_meetings[-1]\n",
"```\n",
"\n",
"## Further Reading\n",
"\n",
"\n",
"\n",
"If you've made it this far, [let me know](https://forms.gle/PDATAmuRS5tAHiiZ8) how you found these notes."
]
}
],
"metadata": {
"jupytext": {
"text_representation": {
"extension": ".md",
"format_name": "myst",
"format_version": 0.12,
"jupytext_version": "1.6.0"
}
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
},
"source_map": [
12,
24,
32,
36,
50,
52,
55,
57,
68,
70,
74,
76,
79,
83,
85,
95,
97,
100,
103,
106,
108,
112,
114,
118,
120,
123,
125,
133,
135,
141,
143,
147,
149,
153,
155,
158,
161,
165,
167,
171,
174,
178,
182,
191,
194,
198,
203,
208,
210,
214,
216,
220,
223,
227,
229,
233,
235,
239,
241
]
},
"nbformat": 4,
"nbformat_minor": 5
}