Skip to content

Commit

Permalink
Added class 22 material
Browse files Browse the repository at this point in the history
  • Loading branch information
emeyers committed Mar 16, 2022
1 parent 53b6b89 commit 7bc3e26
Show file tree
Hide file tree
Showing 5 changed files with 43,344 additions and 0 deletions.
Binary file added demos/lec22.zip
Binary file not shown.
155 changes: 155 additions & 0 deletions demos/lec22/lec22.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from datascience import *\n",
"import numpy as np\n",
"\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plots\n",
"plots.style.use('fivethirtyeight')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lecture 22"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# write the sum_up_to(k) function - can use a for loop\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# write the sum_up_to(k) function - without a for loop\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tables"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr>\n",
" <th>Year Type</th> <th>Year</th> <th>Organization Group Code</th> <th>Organization Group</th> <th>Department Code</th> <th>Department</th> <th>Union Code</th> <th>Union</th> <th>Job Family Code</th> <th>Job Family</th> <th>Job Code</th> <th>Job</th> <th>Employee Identifier</th> <th>Salaries</th> <th>Overtime</th> <th>Other Salaries</th> <th>Total Salary</th> <th>Retirement</th> <th>Health/Dental</th> <th>Other Benefits</th> <th>Total Benefits</th> <th>Total Compensation</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Calendar </td> <td>2015</td> <td>2 </td> <td>Public Works, Transportation & Commerce</td> <td>WTR </td> <td>PUC Water Department </td> <td>21 </td> <td>Prof & Tech Engineers - Miscellaneous, Local 21 </td> <td>2400 </td> <td>Lab, Pharmacy & Med Techs</td> <td>2481 </td> <td>Water Qualitytech I/II</td> <td>21538 </td> <td>82146 </td> <td>0 </td> <td>0 </td> <td>82146 </td> <td>16942.2 </td> <td>12340.9 </td> <td>6337.73 </td> <td>35620.8 </td> <td>117767 </td>\n",
" </tr>\n",
" <tr>\n",
" <td>Calendar </td> <td>2015</td> <td>2 </td> <td>Public Works, Transportation & Commerce</td> <td>DPW </td> <td>General Services Agency - Public Works</td> <td>12 </td> <td>Carpet, Linoleum and Soft Tile Workers, Local 12</td> <td>7300 </td> <td>Journeyman Trade </td> <td>7393 </td> <td>Soft Floor Coverer </td> <td>5459 </td> <td>32165.8 </td> <td>973.19 </td> <td>848.96 </td> <td>33987.9 </td> <td>0 </td> <td>4587.51 </td> <td>2634.42 </td> <td>7221.93 </td> <td>41209.8 </td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>... (42987 rows omitted)</p>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# load data on SF employees\n",
"sf = Table.read_table('san_francisco_2015.csv')\n",
"sf.show(2)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# What is the Mayor's total compensation? \n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# what proportion of people are making more than $100,000?\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
199 changes: 199 additions & 0 deletions demos/lec22/lec22_sol.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from datascience import *\n",
"import numpy as np\n",
"\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plots\n",
"plots.style.use('fivethirtyeight')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lecture 22"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"55"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def sum_up_to(k):\n",
" if k < 0:\n",
" return \"invalid input fool\"\n",
" \n",
" total = 0\n",
" for i in np.arange(k + 1):\n",
" total = total + i\n",
" return total\n",
"\n",
"\n",
"sum_up_to(10)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"55"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def sum_up_to2(k):\n",
" if k < 0:\n",
" return \"invalid input fool\"\n",
" \n",
" return np.sum(np.arange(k + 1))\n",
"\n",
"\n",
"sum_up_to2(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tables"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr>\n",
" <th>Year Type</th> <th>Year</th> <th>Organization Group Code</th> <th>Organization Group</th> <th>Department Code</th> <th>Department</th> <th>Union Code</th> <th>Union</th> <th>Job Family Code</th> <th>Job Family</th> <th>Job Code</th> <th>Job</th> <th>Employee Identifier</th> <th>Salaries</th> <th>Overtime</th> <th>Other Salaries</th> <th>Total Salary</th> <th>Retirement</th> <th>Health/Dental</th> <th>Other Benefits</th> <th>Total Benefits</th> <th>Total Compensation</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Calendar </td> <td>2015</td> <td>2 </td> <td>Public Works, Transportation & Commerce</td> <td>WTR </td> <td>PUC Water Department </td> <td>21 </td> <td>Prof & Tech Engineers - Miscellaneous, Local 21 </td> <td>2400 </td> <td>Lab, Pharmacy & Med Techs</td> <td>2481 </td> <td>Water Qualitytech I/II</td> <td>21538 </td> <td>82146 </td> <td>0 </td> <td>0 </td> <td>82146 </td> <td>16942.2 </td> <td>12340.9 </td> <td>6337.73 </td> <td>35620.8 </td> <td>117767 </td>\n",
" </tr>\n",
" <tr>\n",
" <td>Calendar </td> <td>2015</td> <td>2 </td> <td>Public Works, Transportation & Commerce</td> <td>DPW </td> <td>General Services Agency - Public Works</td> <td>12 </td> <td>Carpet, Linoleum and Soft Tile Workers, Local 12</td> <td>7300 </td> <td>Journeyman Trade </td> <td>7393 </td> <td>Soft Floor Coverer </td> <td>5459 </td> <td>32165.8 </td> <td>973.19 </td> <td>848.96 </td> <td>33987.9 </td> <td>0 </td> <td>4587.51 </td> <td>2634.42 </td> <td>7221.93 </td> <td>41209.8 </td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>... (42987 rows omitted)</p>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sf = Table.read_table('san_francisco_2015.csv')\n",
"sf.show(2)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"379798.03"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# What is the Mayor's total compensation? \n",
"sf.where('Job', 'Mayor').select(\"Total Compensation\") # in a Table\n",
"sf.where('Job', 'Mayor').column(\"Total Compensation\").item(0) # as a number"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.4875898485659122"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# what proportion of people are making more than $100,000?\n",
"sf.where('Total Compensation', are.above(100000)).num_rows/sf.num_rows"
]
}
],
"metadata": {
"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.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 7bc3e26

Please sign in to comment.