Last active
June 29, 2019 21:13
-
-
Save abrahamrhoffman/0cef74374899e061ea6a28b1c5dde48b to your computer and use it in GitHub Desktop.
student_employee_data.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Employer : Student Matcher" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Instantiate classes\n", | |
"import pandas as pd\n", | |
"import numpy as np\n", | |
"\n", | |
"# Import the anax database class\n", | |
"import anax" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Create a new anax database\n", | |
"anax.Database(bootstrap=True);\n", | |
"# Connect to the anax database\n", | |
"anax = anax.Database()\n", | |
"# Remove the example anax table\n", | |
"anax.remove(\"users\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Create a student table" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"students = [\"abe\",\"jason\",\"steve\",\"rudolpho\"]\n", | |
"student_table = {\"students\": students}\n", | |
"anax.create(\"students\", student_table)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"['students']" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"anax.tables()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>students</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>abe</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>jason</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>steve</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>rudolpho</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" students\n", | |
"0 abe\n", | |
"1 jason\n", | |
"2 steve\n", | |
"3 rudolpho" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"anax.read(\"students\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Add some features to our students" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Read the table into a dataframe\n", | |
"students = anax.read(\"students\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Add age, graduation_date, gpa, and top extracirricular activity\n", | |
"students.insert(1, \"age\", [21, 21, 42, 19], True)\n", | |
"students.insert(2, \"graduation_date\", [2021, 2021, 2020, 2023], True)\n", | |
"students.insert(3, \"gpa\", [4.0, 4.0, 3.2, 3.8], True)\n", | |
"students.insert(4, \"extra_activity\", [\"math\", \"badassery\", \"drinking\", np.nan], True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>students</th>\n", | |
" <th>age</th>\n", | |
" <th>graduation_date</th>\n", | |
" <th>gpa</th>\n", | |
" <th>extra_activity</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>abe</td>\n", | |
" <td>21</td>\n", | |
" <td>2021</td>\n", | |
" <td>4.0</td>\n", | |
" <td>math</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>jason</td>\n", | |
" <td>21</td>\n", | |
" <td>2021</td>\n", | |
" <td>4.0</td>\n", | |
" <td>badassery</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>steve</td>\n", | |
" <td>42</td>\n", | |
" <td>2020</td>\n", | |
" <td>3.2</td>\n", | |
" <td>drinking</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>rudolpho</td>\n", | |
" <td>19</td>\n", | |
" <td>2023</td>\n", | |
" <td>3.8</td>\n", | |
" <td>None</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" students age graduation_date gpa extra_activity\n", | |
"0 abe 21 2021 4.0 math\n", | |
"1 jason 21 2021 4.0 badassery\n", | |
"2 steve 42 2020 3.2 drinking\n", | |
"3 rudolpho 19 2023 3.8 None" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Write the new information back to disk\n", | |
"anax.write(students, \"students\")\n", | |
"# Confirm the data is present on disk\n", | |
"anax.read(\"students\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Create employer data for a single employer" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"employees = [\"george\",\"sam\",\"ed\",\"tim\"]\n", | |
"employee_table = {\"employees\": employees}\n", | |
"anax.create(\"acme_employees\", employee_table)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"['students', 'acme_employees']" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"anax.tables()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>employees</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>george</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>sam</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>ed</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>tim</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" employees\n", | |
"0 george\n", | |
"1 sam\n", | |
"2 ed\n", | |
"3 tim" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"anax.read(\"acme_employees\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Add some features to our employees" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Read the table into a dataframe\n", | |
"acme_employees = anax.read(\"acme_employees\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Add age, performance (1-10), interests, and salary data\n", | |
"acme_employees.insert(1, \"age\", [21, 21, 59, 45], True)\n", | |
"acme_employees.insert(2, \"performance\", [9.5, 9.5, 6.0, 3.0], True)\n", | |
"acme_employees.insert(3, \"interests\", [\"math\", \"badassery\", np.nan, np.nan], True)\n", | |
"acme_employees.insert(4, \"salary\", [200000, 220000, 115000, 83000], True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>employees</th>\n", | |
" <th>age</th>\n", | |
" <th>performance</th>\n", | |
" <th>interests</th>\n", | |
" <th>salary</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>george</td>\n", | |
" <td>21</td>\n", | |
" <td>9.5</td>\n", | |
" <td>math</td>\n", | |
" <td>200000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>sam</td>\n", | |
" <td>21</td>\n", | |
" <td>9.5</td>\n", | |
" <td>badassery</td>\n", | |
" <td>220000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>ed</td>\n", | |
" <td>59</td>\n", | |
" <td>6.0</td>\n", | |
" <td>None</td>\n", | |
" <td>115000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>tim</td>\n", | |
" <td>45</td>\n", | |
" <td>3.0</td>\n", | |
" <td>None</td>\n", | |
" <td>83000</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" employees age performance interests salary\n", | |
"0 george 21 9.5 math 200000\n", | |
"1 sam 21 9.5 badassery 220000\n", | |
"2 ed 59 6.0 None 115000\n", | |
"3 tim 45 3.0 None 83000" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Write the new information back to disk\n", | |
"anax.write(acme_employees, \"acme_employees\")\n", | |
"# Confirm the data is present on disk\n", | |
"anax.read(\"acme_employees\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Show completed tables" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>students</th>\n", | |
" <th>age</th>\n", | |
" <th>graduation_date</th>\n", | |
" <th>gpa</th>\n", | |
" <th>extra_activity</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>abe</td>\n", | |
" <td>21</td>\n", | |
" <td>2021</td>\n", | |
" <td>4.0</td>\n", | |
" <td>math</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>jason</td>\n", | |
" <td>21</td>\n", | |
" <td>2021</td>\n", | |
" <td>4.0</td>\n", | |
" <td>badassery</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>steve</td>\n", | |
" <td>42</td>\n", | |
" <td>2020</td>\n", | |
" <td>3.2</td>\n", | |
" <td>drinking</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>rudolpho</td>\n", | |
" <td>19</td>\n", | |
" <td>2023</td>\n", | |
" <td>3.8</td>\n", | |
" <td>None</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" students age graduation_date gpa extra_activity\n", | |
"0 abe 21 2021 4.0 math\n", | |
"1 jason 21 2021 4.0 badassery\n", | |
"2 steve 42 2020 3.2 drinking\n", | |
"3 rudolpho 19 2023 3.8 None" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"anax.read(\"students\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>employees</th>\n", | |
" <th>age</th>\n", | |
" <th>performance</th>\n", | |
" <th>interests</th>\n", | |
" <th>salary</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>george</td>\n", | |
" <td>21</td>\n", | |
" <td>9.5</td>\n", | |
" <td>math</td>\n", | |
" <td>200000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>sam</td>\n", | |
" <td>21</td>\n", | |
" <td>9.5</td>\n", | |
" <td>badassery</td>\n", | |
" <td>220000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>ed</td>\n", | |
" <td>59</td>\n", | |
" <td>6.0</td>\n", | |
" <td>None</td>\n", | |
" <td>115000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>tim</td>\n", | |
" <td>45</td>\n", | |
" <td>3.0</td>\n", | |
" <td>None</td>\n", | |
" <td>83000</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" employees age performance interests salary\n", | |
"0 george 21 9.5 math 200000\n", | |
"1 sam 21 9.5 badassery 220000\n", | |
"2 ed 59 6.0 None 115000\n", | |
"3 tim 45 3.0 None 83000" | |
] | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"anax.read(\"acme_employees\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment