changed HW links

main
Andrew Riddle 5 years ago
parent e19fcdcd69
commit af87806e43

@ -0,0 +1,145 @@
<!---
This guide was developed by Susi Remondi for COHORT NAME / DATE / LOCATION HERE.
Questions? Comments?
1. Log an issue to this repo to alert me of a problem.
2. Suggest an edit yourself by forking this repo, making edits, and submitting a pull request with your changes back to our master branch.
3. Hit me up on Slack @susiremondi
--->
![](https://ga-dash.s3.amazonaws.com/production/assets/logo-9f88ae6c9c3871690e33280fcf557f33.png)
# Python Programming
---
> This course introduces beginners to the Python programming language, with a brief working intro to Data Science (Pandas).
## Overview
In this Python Programming course, students will walk away with a solid foundation in Python, able to confidently build basic applications. Students will also get an 8 hour dive into Pandas (for Data Science), and walk away with a project of their choosing they've built using that library.
## Quick Links
- [Course Details](#course-details)
- [Schedule](#schedule)
## Course Details
Python Programming is a 40-hour course, delivered in a 5 day full-time format. There is no admittance requirement - this course is open to and encouraged for absolute beginners.
Once enrolled, students complete 2 hours of pre-work on the myGA platform.
## Instructional Team
|Role | | GA Profile | Contact |
| :--- | :--- | :--- | :--- |
| Lead Instructor (LI) | <img src="deployment/images/GA_Headshots_055.jpg" height="50"> | [Andrew Riddle](https://generalassemb.ly/instructors/andrew-riddle/21916) | andrew.riddle@generalassemb.ly |
## Final Project
Details for the final project can be found [here](unit-7-data-wrap-up/02-project)
Example projects from previous classes [here](https://drive.google.com/drive/folders/1wEz_sRjoYmwY-u8I9saa9ItZrKOhkqia)
(no need to create a presentation, just make sure your .ipynb file has Markdown fields of text)
Submissions: you will collect all relevant files for your project into a Google Drive folder and submit the shareable link via Slack DM.
Make sure the cells in your Jupyter notebook have been run before saving so we can see all results without having to re-run.
## Schedule
Day 1 | Day 2 | Day 3 | Day 4 | Day 5 | Day 6 |
---- | --- | --- | ---| --- | --- |
[:30] Course Introductions | [:30] Day 2 Kickoff & Review | [:30] Day 3 Kickoff & Review | [:30] Day 4 Kickoff & Review | [:30] Day 5 Kickoff & Review | [3:00] [In-Class: Final Project Workshop][6-1C] |
[:30] Python Installations | [1:00] [Functions (cont'd)][2-1B] | [:30] [Inheritance][3-1A] | [:45] [Modules & Libraries][4-1E] | [:30] [Intro to Charts][5-1E2] | [1:00] Lunch |
[:05] Break | [:10] Break | [:05] Break | [:10] Break | [:05] Break | [1:30] [Project Presentations][6-1E] |
[1:00] [Defining Variables][1-1B] | [1:15] [Advanced Arguments][2-1C] | [1:00] [Lab #3: OOP][3-1C] | [:30] [Intro to Python for Data][5-1B] | [1:00] [Plots and Charts][5-1E] | [:30] [Wrap-up & Celebrations][6-1G] |
[:10] [Lab #1: Fundamentals][1-1D] | [:10] Break | [:10] Break | [:05] Break | [:10] Break | -- |
[:10] Break | [:20] [Lab #2: Control Flow][2-1D] | [:45] [Variable Scope][3-1D] | [1:30] [Pandas1][5-1C] ([Code][5-1C2]) | [1:00] [Pandas Datetime][5-1I] | -- |
[1:00] [Conditionals][1-1E] | [1:00] Lunch | [:15] Mid-Week Check-in | [1:00] Lunch | [1:00] Lunch | -- |
[1:00] Lunch | [:45] [Dictionaries][2-1E] | [1:00] Lunch | [:30] [Pandas 1 (cont'd)][5-1C] ([Code][5-1C2]) | [1:00] [Pandas Joins][5-1J] | -- |
[1:00] [Lists][1-1F] | [:05] Break | [:45] [Debugging Principles][3-1F] | [:05] Break | [:05] Break | -- |
[:05] Break | [:45] [Sets & Tuples][2-1F] | [:05] Break | [1:30] [Pandas 2][5-1F] | [1:15] [Lab #6: Pandas][5-1G] | -- |
[1:00] [Loops][1-1G] | [:05] Break | [1:00] [Lab #4: Debugging][3-1G] | [:10] Break | [:10] Break | -- |
[:05] Break | [1:15] [Classes][2-1G] | [:10] Break | [:15] Final Project Discussion | [:45] Independent Work/Review | -- |
[1:00] [Functions][2-1B] | [:10] End-of-Day Recap | [:30] [Intermediate Python Discussion][4-1B] | [:30] Independent Work/Review | [:30] [End-of-Day Recap][5-1H] | -- |
[:10] End-of-Day Recap | -- | [:30] Independent Work/Review | [:10] End-of-Day Recap | -- | -- |
-- | -- | [:10] End-of-Day Recap | -- | -- | -- |
[1-1A]: unit-1-variables/01-welcome
[1-1B]: unit-1-variables/02-variables/variables_starter.ipynb
[1-1D]: unit-1-variables/03-unit-lab-1/starter-code/starter.ipynb
[1-1E]: unit-2-control-flow/04-conditionals/conditionals_starter.ipynb
[1-1F]: unit-2-control-flow/05-lists/lists_starter.ipynb
[1-1G]: unit-2-control-flow/06-loops/loops_starter.ipynb
[2-1B]: unit-2-control-flow/07-functions/functions_starter.ipynb
[2-1C]: unit-2-control-flow/08-args/args_starter.ipynb
[2-1D]: unit-2-control-flow/09-unit-lab-2/starter-code/starter.ipynb
[2-1E]: unit-3-oop/10-dictionaries/dictionary_starter.ipynb
[2-1F]: unit-3-oop/11-sets-tuples/sets-tuples_starter.ipynb
[2-1G]: unit-3-oop/12-classes/classes_starter.ipynb
[3-1A]: unit-3-oop/13-inheritance/inheritance_starter.ipynb
[3-1B]: unit-3-oop/13-inheritance
[3-1C]: unit-3-oop/14-unit-lab-3/starter-code/starter.ipynb
[3-1D]: unit-4-troubleshooting/15-variable-scope/variable-scope_starter.ipynb
[3-1E]: unit-4-troubleshooting/16-intermediate-variables
[3-1F]: unit-4-troubleshooting/17-debugging/debugging_starter.ipynb
[3-1G]: unit-4-troubleshooting/18-unit-lab-4/starter-code/starter.ipynb
[4-1B]: unit-5-intermediate/19-intermediate-intro/intermed-intro.ipynb
[4-1C]: unit-5-intermediate/20-scripting/20-scripting_starter.ipynb?instructor=1#/scripting-part-1-files
[4-1E]: unit-5-intermediate/22-modules/modules_starter.ipynb
[4-1F]: unit-5-intermediate/23-apis/23-api_starter.ipynb?instructor=1#/section
[4-1G]: unit-5-intermediate/24-unit-lab-5/starter-code/starter.ipynb
[5-1B]: unit-6-pandas/01-ds-intro/01-ds-intro-slides.md
[5-1C]: unit-6-pandas/02-pandas-i/02-pandas-i.md
[5-1C2]: unit-6-pandas/02-pandas-i/code/intro-to-pandas-i.ipynb
[5-1D]: unit-6-pandas/04-data-viz
[5-1E]: unit-6-pandas/05-plotting-with-pandas/code/05-plotting-with-pandas.ipynb
[5-1E2]: unit-6-pandas/04-data-viz/04-data-viz-slides.md
[5-1F]: unit-6-pandas/03-pandas-ii/code/pandas-ii.ipynb
[5-1G]: unit-6-pandas/06-pandas-unit-lab/code/Pandas-Unit-Lab.ipynb
[5-1H]: unit-6-pandas/07-next-steps
[5-1I]: unit-6-pandas/08-pandas-datetime/code/pandas-datetime.ipynb
[5-1J]: unit-6-pandas/09-pandas-join/code/pandas-join.ipynb
[6-1A]: unit-7-data-wrap-up/01-review
[6-1B]: unit-7-web-dev-wrap-up/01-review
[6-1C]: unit-7-data-wrap-up/02-project
[6-1D]: unit-7-web-dev-wrap-up/02-project
[6-1E]: unit-7-data-wrap-up/02-project
[6-1F]: unit-7-web-dev-wrap-up/02-project
[6-1G]: unit-7-data-wrap-up/03-summary
[6-1H]: unit-7-web-dev-wrap-up/03-summary
<!--
[Day1]: course recording links go here
[Day2]:
[Day3]:
[Day4]:
[Day5]:
--->
Day | Suggested Homework
-------- | ---------
1 | [Lists, `if/elif/else`, and `for/while`][7-1A]
2 | [Functions, Dictionaries, *Bonus: Kwargs*][7-1B]
3 | [Type Conversion, TRY/EXCEPT, Debugging ][7-1C]
4 | [Pandas EDA, Pandas Visualizations][7-1D]
5 | Work on final project, [Consumer Sales Exercise][7-1E]
<!--
[5-2B]: unit-6-flask/01-web-dev-intro
[5-2C]: unit-6-flask/02-flask
[5-2D]: unit-6-flask/03-styling-flask
[5-2E]: unit-6-flask/04-flask-routing
[5-2F]: unit-6-flask/05-flask-templates
[5-2G]: unit-6-flask/06-flask-apis
[5-2H]: unit-6-flask/07-flask-unit-lab
[5-2I]: unit-6-flask/08-next-steps
--->
[7-1A]: unit-1-variables/hw-5day-day1/hw_day1.ipynb
[7-1B]: unit-2-control-flow/hw-5day-day2/hw_day2.ipynb
[7-1C]: unit-5-intermediate/hw-5day-day3/hw_day3.ipynb
[7-1D]: unit-6-pandas/hw-5day-4pandas/code/lab.ipynb
[7-1E]: unit-6-pandas/10-pandas-consumersales/code/lab.ipynb

@ -137,9 +137,9 @@ Day | Suggested Homework
[5-2H]: unit-6-flask/07-flask-unit-lab
[5-2I]: unit-6-flask/08-next-steps
--->
[7-1A]: unit-1-variables/hw-5day-day1
[7-1B]: unit-2-control-flow/hw-5day-day2
[7-1C]: unit-5-intermediate/hw-5day-day3
[7-1D]: unit-6-pandas/hw-5day-4pandas
[7-1E]: unit-6-pandas/10-pandas-consumersales
[7-1A]: unit-1-variables/hw-5day-day1/hw_day1.ipynb
[7-1B]: unit-2-control-flow/hw-5day-day2/hw_day2.ipynb
[7-1C]: unit-5-intermediate/hw-5day-day3/hw_day3.ipynb
[7-1D]: unit-6-pandas/hw-5day-4pandas/code/lab.ipynb
[7-1E]: unit-6-pandas/10-pandas-consumersales/code/lab.ipynb

@ -304,5 +304,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

@ -212,47 +212,11 @@
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"wheaties is icky and has 8 characters.\n",
"Froot loops is delicious and has 10 characters.\n",
"cap'n crunch is delicious and has 11 characters.\n"
]
}
],
"source": [
"# A:\n",
"cereals = [\"wheaties\", \"Froot loops\", \"cap'n crunch\"]\n",
"for i in range(len(cereals)):\n",
" if len(cereals[i].replace(\" \", \"\")) >= 10:\n",
" print(f\"{cereals[i]} is delicious and has {len(cereals[i].replace(' ',''))} characters.\")\n",
" if len(cereals[i].replace(\" \",\"\")) < 10:\n",
" print(f\"{cereals[i]} is icky and has {len(cereals[i].replace(' ', ''))} characters.\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'wheaties'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"cereals[0].replace(\" \",\"\")"
"# A:"
]
},
{
@ -340,5 +304,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

@ -72,23 +72,11 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:\n",
"def get_contact(contacts, name):\n",
" \n",
"\n",
"\n",
"contacts = {\n",
" \"Carly\": \"333-3333\",\n",
" \"Blondie\": \"444-4444\",\n",
" \"Jenny\": \"867-5309\"\n",
"}\n",
"name = \"Jenny\"\n",
"\n",
"phone_number = get_contact(contacts, name)"
"# A:"
]
},
{
@ -140,7 +128,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -182,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -276,7 +264,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -389,7 +377,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -427,7 +415,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -455,5 +443,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

@ -72,33 +72,11 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"'Bob' not found in contacts.\n"
]
}
],
"outputs": [],
"source": [
"# A:\n",
"def get_contact(contacts, name):\n",
" if name in contacts.keys():\n",
" return contacts[name]\n",
" print(f\"'{name}' not found in contacts.\")\n",
"\n",
"\n",
"contacts = {\n",
" \"Carly\": \"333-3333\",\n",
" \"Blondie\": \"444-4444\",\n",
" \"Jenny\": \"867-5309\"\n",
"}\n",
"name = \"Jenny\"\n",
"\n",
"get_contact(contacts, 'Bob')\n"
"# A:"
]
},
{
@ -150,35 +128,11 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'b': 1, 'a': 3, 'n': 2}\n"
]
}
],
"outputs": [],
"source": [
"# A:\n",
"def letter_counter(string):\n",
" \n",
" counts = {}\n",
" for char in string:\n",
" if char in counts.keys():\n",
" counts[char] += 1\n",
" else:\n",
" counts[char] = 1\n",
"\n",
" return counts\n",
"\n",
"word_to_count = \"banana\"\n",
"\n",
"result = letter_counter(word_to_count)\n",
"\n",
"print(result)"
"# A:"
]
},
{
@ -216,29 +170,11 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'garlic salt', 'ginger', 'lemon pepper'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# A:\n",
"spices_onhand = ['cumin', 'nutmeg', 'salt', 'cumin', 'star anise', 'salt', 'basil', 'nutmeg', 'cumin', 'paprika', 'curry powder', 'pepper', 'curry powder', 'curry powder', 'cayenne', 'cumin', 'star anise', 'star anise', 'curry powder', 'salt', 'salt', 'cardamom', 'cayenne', 'star anise', 'chili powder', 'curry powder', 'thyme', 'thyme', 'cayenne', 'nutmeg', 'basil', 'star anise', 'chili powder', 'oregano', 'coriander', 'nutmeg', 'chili powder', 'coriander', 'paprika', 'pepper', 'thyme', 'nutmeg', 'paprika', 'cayenne', 'basil', 'cinnamon', 'curry powder', 'cardamom', 'star anise', 'pepper', 'salt', 'curry powder', 'thyme', 'cardamom', 'salt', 'pepper', 'paprika', 'salt', 'cinnamon', 'cumin', 'curry powder', 'cardamom', 'cumin', 'cardamom', 'oregano', 'cardamom', 'pepper', 'star anise', 'pepper', 'cayenne', 'chili powder', 'cardamom', 'nutmeg', 'pepper', 'cardamom', 'curry powder', 'thyme', 'basil', 'nutmeg', 'coriander', 'paprika', 'curry powder', 'cayenne', 'cumin', 'nutmeg', 'paprika', 'star anise', 'thyme', 'curry powder', 'cardamom', 'oregano', 'basil', 'cinnamon', 'oregano', 'coriander', 'curry powder', 'cumin', 'thyme', 'pepper', 'thyme', 'cardamom', 'cayenne', 'chili powder', 'basil', 'pepper', 'cumin', 'thyme', 'cardamom', 'star anise', 'cayenne', 'cinnamon', 'cinnamon', 'cinnamon', 'cardamom', 'curry powder', 'curry powder', 'pepper', 'chili powder', 'pepper', 'cinnamon', 'cardamom', 'basil', 'thyme', 'cinnamon', 'cumin', 'nutmeg', 'cinnamon', 'cayenne', 'cardamom', 'nutmeg', 'cardamom', 'paprika', 'cumin', 'cayenne', 'chili powder', 'cinnamon', 'cumin', 'star anise', 'cardamom', 'thyme', 'basil', 'paprika', 'basil', 'oregano', 'cardamom', 'pepper', 'oregano', 'nutmeg', 'nutmeg', 'salt', 'basil', 'cayenne', 'oregano', 'star anise', 'star anise', 'oregano', 'salt', 'pepper', 'cinnamon', 'basil', 'salt', 'cardamom', 'cayenne', 'oregano', 'cinnamon', 'pepper', 'cumin', 'thyme', 'thyme', 'oregano', 'oregano', 'star anise', 'paprika', 'thyme', 'cinnamon', 'cinnamon', 'oregano', 'star anise', 'oregano', 'chili powder', 'cayenne', 'oregano', 'cumin', 'paprika', 'nutmeg', 'star anise', 'coriander', 'star anise', 'nutmeg', 'chili powder', 'star anise', 'paprika', 'salt', 'salt', 'cayenne', 'curry powder', 'thyme', 'oregano', 'curry powder', 'curry powder']\n",
"\n",
"spices_needed = set({\"salt\", \"pepper\", \"ginger\", \"oregano\", \"paprika\", \"basil\", \"curry powder\", \"cumin\", \"cayenne\", \"lemon pepper\", \"chili powder\", \"nutmeg\", \"cinnamon\", \"star anise\", \"garlic salt\", \"coriander\", \"cardamom\", \"thyme\"})\n",
"\n",
"spices_onhand = set(spices_onhand)\n",
"\n",
"spices_needed.difference(spices_onhand)"
"# A:"
]
},
{
@ -328,7 +264,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -441,7 +377,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -477,83 +413,14 @@
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Velociraptor is small! Mighty Kwargosaurus will fight you!\n",
"Stegosaurus is small! Mighty Kwargosaurus will fight you!\n",
"Triceratops is small! Mighty Kwargosaurus will fight you!\n",
"Trex is big! Whimpering Kwargosaurus cries and runs away!\n"
]
}
],
"source": [
"# A:\n",
"def kwargosaurus(**kwargs):\n",
" for dino, size in kwargs.items():\n",
" if size == 'smaller':\n",
" print(f\"{dino} is small! Mighty Kwargosaurus will fight you!\")\n",
" else:\n",
" print(f\"{dino} is big! Whimpering Kwargosaurus cries and runs away!\")\n",
"\n",
"\n",
"kwargosaurus(Velociraptor=\"smaller\", Stegosaurus=\"smaller\", \n",
" Triceratops=\"smaller\", Trex=\"bigger\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x, y = (1,2)\n",
"x"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('a', 1), ('b', 2)]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list({'a':1,'b':2}.items())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# A:"
]
}
],
"metadata": {
@ -576,5 +443,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

@ -0,0 +1,186 @@
### ![](https://ga-dash.s3.amazonaws.com/production/assets/logo-9f88ae6c9c3871690e33280fcf557f33.png) Python Programming
<!---
This assignment was developed by Brandi
Questions? Comments?
1. Log an issue to this repo to alert me of a problem.
2. Suggest an edit yourself by forking this repo, making edits, and submitting a pull request with your changes back to our master branch.
3. Hit me up on Slack at @brandib.
--->
# Advanced Python: Practice Problems
In this homework, you're going to write code for a few problems. Like before, we'll be practicing new material, but you may need to break out your skills from previous units.
You will practice these programming concepts we've covered in class:
* Using `itertools` and `random` functions.
* Type conversion and more advanced variable usage.
* Calling an API to get data using `requests`.
* Debugging code that doesn't work using `print` statements.
* Scripting and file I/O.
* Using list comprehensions to simplify list creation.
------------
## Deliverables
For each of the challenges listed below, you will create a new `.py` file and write code to solve the problem. For example, you would create `problem1.py` with your solution code to the first problem. Run the file from the command line to check your work.
*Reminder: On your laptop, you can run the file from your command line with the following:*
```python
python problem1.py
```
> **Hint:** Make sure you are printing something out with the `print` statement. Otherwise, you won't see any output from running your program!
## Requirements:
* By the end of this, you should have five different `.py` files (one for each problem).
------------
## Problem 1:
### Skills you're practicing: Generating random numbers and type conversion.
Make your own version of the `Guess a Number` game. Generate a random integer and store it in a variable called `answer`. Print a statement asking the user to guess a number.
If the user's guess is:
* Higher than the `answer`: print `That is too high!`.
* Lower than the `answer`: print `That is too low!`.
* Exactly the `answer`: print `That's it! You win!`.
Your program should keep prompting the user until they enter the correct answer.
#### Example Output
```
I'm thinking of a number between 1 and 10.
Please guess what it is:
> 4
That is too low!
> 8
That is too high!
> 6
That's it! You win!
```
> **Hint 1:** User input comes to you as a string. How can you make it into an integer so you can properly compare the user's guess with the `answer` (which is an integer)?
> **Hint 2:** You can set a variable to `False` or `True`.
------------
## Problem 2: D'oh!
### Skills you're practicing: Using `try`/`except` statements and error handling.
Bart Simpson has gotten ahold of your program from Problem 1 and started entering a bunch of values that are NOT numbers! How do you handle it?
Create a new file with your code from Problem 1 and modify it to print `D'oh! That is NOT a number, Bart!` if the user doesn't enter an integer.
#### Example Output
```
I'm thinking of a number between 1 and 10.
Please guess what it is:
> Eat my shorts!
D'oh! That is NOT a number, Bart!
Please guess what it is:
> Ay, caramba!
D'oh! That is NOT a number, Bart!
Please guess what it is:
> 5
That is too low!
Please guess what it is:
> 8
That's it! You win!
```
> **Hint:** The `continue` keyword can be called in a loop and means "skip the rest of this loop iteration." It may be useful to call this in an `except` clause.
------------
## Problem 3:
### Skill you're practicing: Debugging built-in errors.
Copy the code out of the repl.it below into your file and fix the errors in the code. Don't change the `rainbow`'s contents.
<iframe height="400px" width="100%" src="https://repl.it/@GAcoding/python-programming-eod-hw-3?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
#### Expected Output
```
The rainbow's name is Roy G. Biv
I'll be taking that gold!
red
orange
yellow
green
blue
What color is indigo?
violet
102
100.0
```
> **Hint:** You may encounter: `NameError`, `SyntaxError`, `IndentationError`, `KeyError`, `TypeError`, etc. Refer to the class notes for common causes of these errors.
------------
## Problem 4: Three Commas
### Skill you're practicing: Formatting numbers.
Russ is a billionaire and he'd like to count his wealth in the number of commas it contains. For example, someone who is a millionaire would have only two commas (1,000,000). Russ, however, has three commas and would like to see those commas displayed. Help Russ format his integer so that commas appear when it is printed out. Make sure your program will work for any value of `wealth`.
#### Example Code
```python
wealth = 1000000000
```
#### Example Output
```
1,000,000,000
```
> **Hint:** Look up `format` if you've forgotten how to use it!
------------
## Problem 5: My Favorite TV Characters
### Skills you're practicing: Scripting and debugging.
I'm trying to write a list of favorite TV show characters to a file called `my_characters`. I'm nearly there, but instead of printing the whole list, I'm just getting the last line. Help me out: Can you get the whole list to print to a file?
#### My Code
https://repl.it/@GAcoding/python-programming-hw-eod-3-prob-5?lite=true
#### Desired Output
```
1: Will Byers
2: Tyrion Lannister
3: Oliver Queen
4: Jean-Luc Picard
5: Malcolm Reynolds
6: The Doctor
7: Sam Winchester
8: Sherlock Holmes
```
#### Actual Output
```
8: Sherlock Holmes
```
> **Hint:** Remember the [spreadsheet](https://www.dropbox.com/s/cqsxfws52gulkyx/drawing.pdf) we looked at earlier? See if it can help!
------------
## Last, But Not Least
You're all done! Wow! Time for a well-earned break!
![](https://media.giphy.com/media/SJsuD0XD2zNug/giphy.gif)

@ -0,0 +1,304 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "comprehensive-requirement",
"metadata": {},
"source": [
"# Advanced Python: Practice Problems\n",
"\n",
"In this homework, you're going to write code for a few problems. Like before, we'll be practicing new material, but you may need to break out your skills from previous units.\n",
"\n",
"You will practice these programming concepts we've covered in class:\n",
"* Using `itertools` and `random` functions.\n",
"* Type conversion and more advanced variable usage.\n",
"* Calling an API to get data using `requests`.\n",
"* Debugging code that doesn't work using `print` statements.\n",
"* Scripting and file I/O.\n",
"* Using list comprehensions to simplify list creation."
]
},
{
"cell_type": "markdown",
"id": "extensive-engagement",
"metadata": {},
"source": [
"---\n",
"## Problem 1:\n",
"\n",
"### Skills you're practicing: Generating random numbers and type conversion.\n",
"\n",
"Make your own version of the `Guess a Number` game. Generate a random integer and store it in a variable called `answer`. Print a statement asking the user to guess a number.\n",
"\n",
"If the user's guess is:\n",
"* Higher than the `answer`: print `That is too high!`.\n",
"* Lower than the `answer`: print `That is too low!`.\n",
"* Exactly the `answer`: print `That's it! You win!`.\n",
"\n",
"Your program should keep prompting the user until they enter the correct answer.\n",
"\n",
"#### Example Output\n",
"```\n",
"I'm thinking of a number between 1 and 10.\n",
"Please guess what it is:\n",
"> 4\n",
"That is too low!\n",
"> 8\n",
"That is too high!\n",
"> 6\n",
"That's it! You win!\n",
"```\n",
"\n",
"> **Hint 1:** User input comes to you as a string. How can you make it into an integer so you can properly compare the user's guess with the `answer` (which is an integer)?\n",
"\n",
"> **Hint 2:** You can set a variable to `False` or `True`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "civilian-ambassador",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "representative-month",
"metadata": {},
"source": [
"---\n",
"## Problem 2: D'oh!\n",
"\n",
"### Skills you're practicing: Using `try`/`except` statements and error handling.\n",
"\n",
"Bart Simpson has gotten ahold of your program from Problem 1 and started entering a bunch of values that are NOT numbers! How do you handle it?\n",
"\n",
"Modify your code from Problem 1 to print `D'oh! That is NOT a number, Bart!` if the user doesn't enter an integer.\n",
"\n",
"#### Example Output\n",
"```\n",
"I'm thinking of a number between 1 and 10.\n",
"Please guess what it is:\n",
"> Eat my shorts!\n",
"D'oh! That is NOT a number, Bart!\n",
"Please guess what it is:\n",
"> Ay, caramba!\n",
"D'oh! That is NOT a number, Bart!\n",
"Please guess what it is:\n",
"> 5\n",
"That is too low!\n",
"Please guess what it is:\n",
"> 8\n",
"That's it! You win!\n",
"```\n",
"\n",
"> **Hint:** The `continue` keyword can be called in a loop and means \"skip the rest of this loop iteration.\" It may be useful to call this in an `except` clause."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "important-harvey",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "advanced-blackberry",
"metadata": {},
"source": [
"---\n",
"## Problem 3:\n",
"\n",
"### Skill you're practicing: Debugging built-in errors.\n",
"\n",
"Fix the errors in the code. Don't change the `rainbow`'s contents.\n",
"\n",
"#### Expected Output\n",
"```\n",
"The rainbow's name is Roy G. Biv\n",
"I'll be taking that gold!\n",
"red\n",
"orange\n",
"yellow\n",
"green\n",
"blue\n",
"What color is indigo?\n",
"violet\n",
"102\n",
"100.0\n",
"```\n",
"\n",
"> **Hint:** You may encounter: `NameError`, `SyntaxError`, `IndentationError`, `KeyError`, `TypeError`, etc. Refer to the class notes for common causes of these errors."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "solar-concrete",
"metadata": {},
"outputs": [],
"source": [
"# Fix this code below line 11! Don't change the rainbow variable!\n",
"rainbow = {\n",
" \"name\": \"Roy G. Biv\",\n",
" \"colors\": [\"red\", \"orange\", \"yellow\", \"green\", \"blue\", \"indigo\", \"violet\"],\n",
" \"end\": \"Pot Of Gold!\",\n",
" \"number\": \"double\",\n",
" \"count\": 2,\n",
" \"gold\": 100\n",
"}\n",
"\n",
"# ------------------------------------------------------\n",
"# Start Fixing Below Here\n",
"# You may encounter: NameError, SyntaxError, IndentationError, KeyError, TypeError, etc.\n",
"print(\"The rainbow's name is\", rainbow[\"Name\"])\n",
"\n",
"if rainbow[\"end\"] == \"Pot Of Gold!\":\n",
" print(\"I'll be taking that gold!\")\n",
" else:\n",
" print(\"No money for me!\")\n",
"\n",
"while color in rainbow[\"colors\"]:\n",
" if color is not \"Indigo\":\n",
" print(color)\n",
" else: \n",
" print(\"What color is indigo?\")\n",
"\n",
"print(\"This rainbow is a double?\", rainbow[\"double\"])\n",
"\n",
"gold_amount = rainbow[\"number\"] + rainbow[\"gold\"]\n",
"print(gold_amount)\n",
"\n",
"persons = 0\n",
"split_gold = rainbow[\"gold\"] / persons\n",
"print(split_gold)"
]
},
{
"cell_type": "markdown",
"id": "innovative-wilson",
"metadata": {},
"source": [
"---\n",
"## Problem 4: Three Commas\n",
"\n",
"### Skill you're practicing: Formatting numbers.\n",
"\n",
"Russ is a billionaire and he'd like to count his wealth in the number of commas it contains. For example, someone who is a millionaire would have only two commas (1,000,000). Russ, however, has three commas and would like to see those commas displayed. Help Russ format his integer so that commas appear when it is printed out. Make sure your program will work for any value of `wealth`.\n",
"\n",
"#### Example Code\n",
"```python\n",
"wealth = 1000000000\n",
"```\n",
"\n",
"#### Example Output\n",
"```\n",
"1,000,000,000\n",
"```\n",
"\n",
"> **Hint:** Look up `format` if you've forgotten how to use it!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "solved-python",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "attempted-announcement",
"metadata": {},
"source": [
"---\n",
"## Problem 5: My Favorite TV Characters\n",
"\n",
"### Skills you're practicing: Scripting and debugging.\n",
"\n",
"I'm trying to write a list of favorite TV show characters to a file called `my_characters`. I'm nearly there, but instead of printing the whole list, I'm just getting the last line. Help me out: Can you get the whole list to print to a file?\n",
"\n",
"#### My Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "agreed-acquisition",
"metadata": {},
"outputs": [],
"source": [
"tv_characters = [\"Will Byers\", \"Tyrion Lannister\", \"Oliver Queen\", \"Jean Luc Picard\", \"Malcom Reynolds\", \"The Doctor\", \"Sam Winchester\", \"Sherlock Holmes\"]\n",
"\n",
"# Write out my character list to a file called \"text\"\n",
"for index, character in enumerate(tv_characters):\n",
" f = open(\"my_characters\", \"w\")\n",
" f.write(f\"{index+1}: {character}\\n\")\n",
" f.close()"
]
},
{
"cell_type": "markdown",
"id": "registered-consequence",
"metadata": {},
"source": [
"#### Desired Output\n",
"```\n",
"1: Will Byers\n",
"2: Tyrion Lannister\n",
"3: Oliver Queen\n",
"4: Jean-Luc Picard\n",
"5: Malcolm Reynolds\n",
"6: The Doctor\n",
"7: Sam Winchester\n",
"8: Sherlock Holmes\n",
"```\n",
"\n",
"#### Actual Output\n",
"```\n",
"8: Sherlock Holmes\n",
"```\n",
"\n",
"> **Hint:** Remember the [spreadsheet](https://www.dropbox.com/s/cqsxfws52gulkyx/drawing.pdf) we looked at earlier? See if it can help!"
]
},
{
"cell_type": "markdown",
"id": "based-spotlight",
"metadata": {},
"source": [
"---\n",
"## Last, But Not Least\n",
"\n",
"You're all done! Wow! Time for a well-earned break!\n",
"\n",
"![](https://media.giphy.com/media/SJsuD0XD2zNug/giphy.gif)"
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,390 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "hispanic-project",
"metadata": {},
"source": [
"# Advanced Python: Practice Problems\n",
"\n",
"In this homework, you're going to write code for a few problems. Like before, we'll be practicing new material, but you may need to break out your skills from previous units.\n",
"\n",
"You will practice these programming concepts we've covered in class:\n",
"* Using `itertools` and `random` functions.\n",
"* Type conversion and more advanced variable usage.\n",
"* Calling an API to get data using `requests`.\n",
"* Debugging code that doesn't work using `print` statements.\n",
"* Scripting and file I/O.\n",
"* Using list comprehensions to simplify list creation."
]
},
{
"cell_type": "markdown",
"id": "informed-transcription",
"metadata": {},
"source": [
"---\n",
"## Problem 1:\n",
"\n",
"### Skills you're practicing: Generating random numbers and type conversion.\n",
"\n",
"Make your own version of the `Guess a Number` game. Generate a random integer and store it in a variable called `answer`. Print a statement asking the user to guess a number.\n",
"\n",
"If the user's guess is:\n",
"* Higher than the `answer`: print `That is too high!`.\n",
"* Lower than the `answer`: print `That is too low!`.\n",
"* Exactly the `answer`: print `That's it! You win!`.\n",
"\n",
"Your program should keep prompting the user until they enter the correct answer.\n",
"\n",
"#### Example Output\n",
"```\n",
"I'm thinking of a number between 1 and 10.\n",
"Please guess what it is:\n",
"> 4\n",
"That is too low!\n",
"> 8\n",
"That is too high!\n",
"> 6\n",
"That's it! You win!\n",
"```\n",
"\n",
"> **Hint 1:** User input comes to you as a string. How can you make it into an integer so you can properly compare the user's guess with the `answer` (which is an integer)?\n",
"\n",
"> **Hint 2:** You can set a variable to `False` or `True`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "blocked-lottery",
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"\n",
"answer = random.randint(1, 10)\n",
"guessed = False\n",
"\n",
"print(\"I'm thinking of a number between 1 and 10.\")\n",
"\n",
"while not guessed:\n",
" current_guess = int(input(\"Please guess what it is:\"))\n",
"\n",
" if current_guess == answer:\n",
" print(\"That's it! You win!\")\n",
" guessed = True\n",
" elif current_guess < answer:\n",
" print(\"That is too low!\")\n",
" elif current_guess > answer:\n",
" print(\"That is too high!\")"
]
},
{
"cell_type": "markdown",
"id": "static-tuition",
"metadata": {},
"source": [
"---\n",
"## Problem 2: D'oh!\n",
"\n",
"### Skills you're practicing: Using `try`/`except` statements and error handling.\n",
"\n",
"Bart Simpson has gotten ahold of your program from Problem 1 and started entering a bunch of values that are NOT numbers! How do you handle it?\n",
"\n",
"Modify your code from Problem 1 to print `D'oh! That is NOT a number, Bart!` if the user doesn't enter an integer.\n",
"\n",
"#### Example Output\n",
"```\n",
"I'm thinking of a number between 1 and 10.\n",
"Please guess what it is:\n",
"> Eat my shorts!\n",
"D'oh! That is NOT a number, Bart!\n",
"Please guess what it is:\n",
"> Ay, caramba!\n",
"D'oh! That is NOT a number, Bart!\n",
"Please guess what it is:\n",
"> 5\n",
"That is too low!\n",
"Please guess what it is:\n",
"> 8\n",
"That's it! You win!\n",
"```\n",
"\n",
"> **Hint:** The `continue` keyword can be called in a loop and means \"skip the rest of this loop iteration.\" It may be useful to call this in an `except` clause."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "divine-departure",
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"\n",
"answer = random.randint(1, 10)\n",
"guessed = False\n",
"\n",
"print(\"I'm thinking of a number between 1 and 10.\")\n",
"\n",
"while not guessed:\n",
" current_guess = input(\"Please guess what it is:\")\n",
"\n",
" try:\n",
" current_guess = int(current_guess)\n",
" except:\n",
" print(\"D'oh! That is NOT a number, Bart!\")\n",
" continue # This skips the rest of this loop iteration.\n",
"\n",
" if current_guess == answer:\n",
" print(\"That's it! You win!\")\n",
" guessed = True\n",
" elif current_guess < answer:\n",
" print(\"That is too low!\")\n",
" elif current_guess > answer:\n",
" print(\"That is too high!\")"
]
},
{
"cell_type": "markdown",
"id": "floating-victor",
"metadata": {},
"source": [
"---\n",
"## Problem 3:\n",
"\n",
"### Skill you're practicing: Debugging built-in errors.\n",
"\n",
"Fix the errors in the code. Don't change the `rainbow`'s contents.\n",
"\n",
"#### Expected Output\n",
"```\n",
"The rainbow's name is Roy G. Biv\n",
"I'll be taking that gold!\n",
"red\n",
"orange\n",
"yellow\n",
"green\n",
"blue\n",
"What color is indigo?\n",
"violet\n",
"102\n",
"100.0\n",
"```\n",
"\n",
"> **Hint:** You may encounter: `NameError`, `SyntaxError`, `IndentationError`, `KeyError`, `TypeError`, etc. Refer to the class notes for common causes of these errors."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "particular-behavior",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The rainbow's name is Roy G. Biv\n",
"I'll be taking that gold!\n",
"red\n",
"orange\n",
"yellow\n",
"green\n",
"blue\n",
"What color is indigo?\n",
"violet\n",
"102\n",
"100.0\n"
]
}
],
"source": [
"# Fixed Code (You may have some small variations!)\n",
"rainbow = {\n",
" \"name\": \"Roy G. Biv\",\n",
" \"colors\": [\"red\", \"orange\", \"yellow\", \"green\", \"blue\", \"indigo\", \"violet\"],\n",
" \"end\": \"Pot of gold!\",\n",
" \"number\": \"double\",\n",
" \"count\": 2,\n",
" \"gold\": 100\n",
"}\n",
"\n",
"print(\"The rainbow's name is\", rainbow[\"name\"])\n",
"\n",
"if rainbow[\"end\"] == \"Pot of gold!\":\n",
" print(\"I'll be taking that gold!\")\n",
"else:\n",
" print(\"No money for me!\")\n",
"\n",
"for color in rainbow[\"colors\"]:\n",
" if color is not \"indigo\":\n",
" print(color)\n",
" else:\n",
" print(\"What color is indigo?\")\n",
"\n",
"gold_amount = rainbow[\"count\"] + rainbow[\"gold\"]\n",
"print(gold_amount)\n",
"\n",
"persons = 1\n",
"split_gold = rainbow[\"gold\"] / persons\n",
"print(split_gold)"
]
},
{
"cell_type": "markdown",
"id": "perceived-puzzle",
"metadata": {},
"source": [
"---\n",
"## Problem 4: Three Commas\n",
"\n",
"### Skill you're practicing: Formatting numbers.\n",
"\n",
"Russ is a billionaire and he'd like to count his wealth in the number of commas it contains. For example, someone who is a millionaire would have only two commas (1,000,000). Russ, however, has three commas and would like to see those commas displayed. Help Russ format his integer so that commas appear when it is printed out. Make sure your program will work for any value of `wealth`.\n",
"\n",
"#### Example Code\n",
"```python\n",
"wealth = 1000000000\n",
"```\n",
"\n",
"#### Example Output\n",
"```\n",
"1,000,000,000\n",
"```\n",
"\n",
"> **Hint:** Look up `format` if you've forgotten how to use it!"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "indonesian-threat",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1,000,000,000\n"
]
}
],
"source": [
"# We start out with an integer.\n",
"wealth = 1000000000\n",
"\n",
"# We convert it to a string formatted the way we want.\n",
"formatted = format(wealth, ',d')\n",
"\n",
"# Print it out!\n",
"print(formatted)"
]
},
{
"cell_type": "markdown",
"id": "burning-relationship",
"metadata": {},
"source": [
"---\n",
"## Problem 5: My Favorite TV Characters\n",
"\n",
"### Skills you're practicing: Scripting and debugging.\n",
"\n",
"I'm trying to write a list of favorite TV show characters to a file called `my_characters`. I'm nearly there, but instead of printing the whole list, I'm just getting the last line. Help me out: Can you get the whole list to print to a file?\n",
"\n",
"#### My Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "limiting-withdrawal",
"metadata": {},
"outputs": [],
"source": [
"tv_characters = [\"Will Byers\", \"Tyrion Lannister\", \"Oliver Queen\", \"Jean Luc Picard\", \"Malcom Reynolds\", \"The Doctor\", \"Sam Winchester\", \"Sherlock Holmes\"]\n",
"\n",
"# Write out my character list to a file called \"text\"\n",
"for index, character in enumerate(tv_characters):\n",
" f = open(\"text\", \"w\")\n",
" f.write(f\"{index+1}: {character}\\n\")\n",
" f.close()"
]
},
{
"cell_type": "markdown",
"id": "asian-resource",
"metadata": {},
"source": [
"#### Desired Output\n",
"```\n",
"1: Will Byers\n",
"2: Tyrion Lannister\n",
"3: Oliver Queen\n",
"4: Jean-Luc Picard\n",
"5: Malcolm Reynolds\n",
"6: The Doctor\n",
"7: Sam Winchester\n",
"8: Sherlock Holmes\n",
"```\n",
"\n",
"#### Actual Output\n",
"```\n",
"8: Sherlock Holmes\n",
"```\n",
"\n",
"> **Hint:** Remember the [spreadsheet](https://www.dropbox.com/s/cqsxfws52gulkyx/drawing.pdf) we looked at earlier? See if it can help!"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "postal-netherlands",
"metadata": {},
"outputs": [],
"source": [
"tv_characters = [\"Will Byers\", \"Tyrion Lannister\", \"Oliver Queen\", \"Jean-Luc Picard\", \"Malcolm Reynolds\", \"The Doctor\", \"Sam Winchester\", \"Sherlock Holmes\"]\n",
"\n",
"# Open the file outside of the loop.\n",
"f = open(\"my_characters\", \"w\")\n",
"\n",
"for index, character in enumerate(tv_characters):\n",
" f.write(f\"{index+1}: {character}\\n\")\n",
"\n",
"# This happens outside the loop, too.\n",
"f.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fleet-fitness",
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,8 @@
1: Will Byers
2: Tyrion Lannister
3: Oliver Queen
4: Jean-Luc Picard
5: Malcolm Reynolds
6: The Doctor
7: Sam Winchester
8: Sherlock Holmes

@ -0,0 +1,304 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "comprehensive-requirement",
"metadata": {},
"source": [
"# Advanced Python: Practice Problems\n",
"\n",
"In this homework, you're going to write code for a few problems. Like before, we'll be practicing new material, but you may need to break out your skills from previous units.\n",
"\n",
"You will practice these programming concepts we've covered in class:\n",
"* Using `itertools` and `random` functions.\n",
"* Type conversion and more advanced variable usage.\n",
"* Calling an API to get data using `requests`.\n",
"* Debugging code that doesn't work using `print` statements.\n",
"* Scripting and file I/O.\n",
"* Using list comprehensions to simplify list creation."
]
},
{
"cell_type": "markdown",
"id": "extensive-engagement",
"metadata": {},
"source": [
"---\n",
"## Problem 1:\n",
"\n",
"### Skills you're practicing: Generating random numbers and type conversion.\n",
"\n",
"Make your own version of the `Guess a Number` game. Generate a random integer and store it in a variable called `answer`. Print a statement asking the user to guess a number.\n",
"\n",
"If the user's guess is:\n",
"* Higher than the `answer`: print `That is too high!`.\n",
"* Lower than the `answer`: print `That is too low!`.\n",
"* Exactly the `answer`: print `That's it! You win!`.\n",
"\n",
"Your program should keep prompting the user until they enter the correct answer.\n",
"\n",
"#### Example Output\n",
"```\n",
"I'm thinking of a number between 1 and 10.\n",
"Please guess what it is:\n",
"> 4\n",
"That is too low!\n",
"> 8\n",
"That is too high!\n",
"> 6\n",
"That's it! You win!\n",
"```\n",
"\n",
"> **Hint 1:** User input comes to you as a string. How can you make it into an integer so you can properly compare the user's guess with the `answer` (which is an integer)?\n",
"\n",
"> **Hint 2:** You can set a variable to `False` or `True`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "civilian-ambassador",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "representative-month",
"metadata": {},
"source": [
"---\n",
"## Problem 2: D'oh!\n",
"\n",
"### Skills you're practicing: Using `try`/`except` statements and error handling.\n",
"\n",
"Bart Simpson has gotten ahold of your program from Problem 1 and started entering a bunch of values that are NOT numbers! How do you handle it?\n",
"\n",
"Modify your code from Problem 1 to print `D'oh! That is NOT a number, Bart!` if the user doesn't enter an integer.\n",
"\n",
"#### Example Output\n",
"```\n",
"I'm thinking of a number between 1 and 10.\n",
"Please guess what it is:\n",
"> Eat my shorts!\n",
"D'oh! That is NOT a number, Bart!\n",
"Please guess what it is:\n",
"> Ay, caramba!\n",
"D'oh! That is NOT a number, Bart!\n",
"Please guess what it is:\n",
"> 5\n",
"That is too low!\n",
"Please guess what it is:\n",
"> 8\n",
"That's it! You win!\n",
"```\n",
"\n",
"> **Hint:** The `continue` keyword can be called in a loop and means \"skip the rest of this loop iteration.\" It may be useful to call this in an `except` clause."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "important-harvey",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "advanced-blackberry",
"metadata": {},
"source": [
"---\n",
"## Problem 3:\n",
"\n",
"### Skill you're practicing: Debugging built-in errors.\n",
"\n",
"Fix the errors in the code. Don't change the `rainbow`'s contents.\n",
"\n",
"#### Expected Output\n",
"```\n",
"The rainbow's name is Roy G. Biv\n",
"I'll be taking that gold!\n",
"red\n",
"orange\n",
"yellow\n",
"green\n",
"blue\n",
"What color is indigo?\n",
"violet\n",
"102\n",
"100.0\n",
"```\n",
"\n",
"> **Hint:** You may encounter: `NameError`, `SyntaxError`, `IndentationError`, `KeyError`, `TypeError`, etc. Refer to the class notes for common causes of these errors."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "solar-concrete",
"metadata": {},
"outputs": [],
"source": [
"# Fix this code below line 11! Don't change the rainbow variable!\n",
"rainbow = {\n",
" \"name\": \"Roy G. Biv\",\n",
" \"colors\": [\"red\", \"orange\", \"yellow\", \"green\", \"blue\", \"indigo\", \"violet\"],\n",
" \"end\": \"Pot Of Gold!\",\n",
" \"number\": \"double\",\n",
" \"count\": 2,\n",
" \"gold\": 100\n",
"}\n",
"\n",
"# ------------------------------------------------------\n",
"# Start Fixing Below Here\n",
"# You may encounter: NameError, SyntaxError, IndentationError, KeyError, TypeError, etc.\n",
"print(\"The rainbow's name is\", rainbow[\"Name\"])\n",
"\n",
"if rainbow[\"end\"] == \"Pot Of Gold!\":\n",
" print(\"I'll be taking that gold!\")\n",
" else:\n",
" print(\"No money for me!\")\n",
"\n",
"while color in rainbow[\"colors\"]:\n",
" if color is not \"Indigo\":\n",
" print(color)\n",
" else: \n",
" print(\"What color is indigo?\")\n",
"\n",
"print(\"This rainbow is a double?\", rainbow[\"double\"])\n",
"\n",
"gold_amount = rainbow[\"number\"] + rainbow[\"gold\"]\n",
"print(gold_amount)\n",
"\n",
"persons = 0\n",
"split_gold = rainbow[\"gold\"] / persons\n",
"print(split_gold)"
]
},
{
"cell_type": "markdown",
"id": "innovative-wilson",
"metadata": {},
"source": [
"---\n",
"## Problem 4: Three Commas\n",
"\n",
"### Skill you're practicing: Formatting numbers.\n",
"\n",
"Russ is a billionaire and he'd like to count his wealth in the number of commas it contains. For example, someone who is a millionaire would have only two commas (1,000,000). Russ, however, has three commas and would like to see those commas displayed. Help Russ format his integer so that commas appear when it is printed out. Make sure your program will work for any value of `wealth`.\n",
"\n",
"#### Example Code\n",
"```python\n",
"wealth = 1000000000\n",
"```\n",
"\n",
"#### Example Output\n",
"```\n",
"1,000,000,000\n",
"```\n",
"\n",
"> **Hint:** Look up `format` if you've forgotten how to use it!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "solved-python",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "attempted-announcement",
"metadata": {},
"source": [
"---\n",
"## Problem 5: My Favorite TV Characters\n",
"\n",
"### Skills you're practicing: Scripting and debugging.\n",
"\n",
"I'm trying to write a list of favorite TV show characters to a file called `my_characters`. I'm nearly there, but instead of printing the whole list, I'm just getting the last line. Help me out: Can you get the whole list to print to a file?\n",
"\n",
"#### My Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "agreed-acquisition",
"metadata": {},
"outputs": [],
"source": [
"tv_characters = [\"Will Byers\", \"Tyrion Lannister\", \"Oliver Queen\", \"Jean Luc Picard\", \"Malcom Reynolds\", \"The Doctor\", \"Sam Winchester\", \"Sherlock Holmes\"]\n",
"\n",
"# Write out my character list to a file called \"text\"\n",
"for index, character in enumerate(tv_characters):\n",
" f = open(\"my_characters\", \"w\")\n",
" f.write(f\"{index+1}: {character}\\n\")\n",
" f.close()"
]
},
{
"cell_type": "markdown",
"id": "registered-consequence",
"metadata": {},
"source": [
"#### Desired Output\n",
"```\n",
"1: Will Byers\n",
"2: Tyrion Lannister\n",
"3: Oliver Queen\n",
"4: Jean-Luc Picard\n",
"5: Malcolm Reynolds\n",
"6: The Doctor\n",
"7: Sam Winchester\n",
"8: Sherlock Holmes\n",
"```\n",
"\n",
"#### Actual Output\n",
"```\n",
"8: Sherlock Holmes\n",
"```\n",
"\n",
"> **Hint:** Remember the [spreadsheet](https://www.dropbox.com/s/cqsxfws52gulkyx/drawing.pdf) we looked at earlier? See if it can help!"
]
},
{
"cell_type": "markdown",
"id": "based-spotlight",
"metadata": {},
"source": [
"---\n",
"## Last, But Not Least\n",
"\n",
"You're all done! Wow! Time for a well-earned break!\n",
"\n",
"![](https://media.giphy.com/media/SJsuD0XD2zNug/giphy.gif)"
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,390 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "hispanic-project",
"metadata": {},
"source": [
"# Advanced Python: Practice Problems\n",
"\n",
"In this homework, you're going to write code for a few problems. Like before, we'll be practicing new material, but you may need to break out your skills from previous units.\n",
"\n",
"You will practice these programming concepts we've covered in class:\n",
"* Using `itertools` and `random` functions.\n",
"* Type conversion and more advanced variable usage.\n",
"* Calling an API to get data using `requests`.\n",
"* Debugging code that doesn't work using `print` statements.\n",
"* Scripting and file I/O.\n",
"* Using list comprehensions to simplify list creation."
]
},
{
"cell_type": "markdown",
"id": "informed-transcription",
"metadata": {},
"source": [
"---\n",
"## Problem 1:\n",
"\n",
"### Skills you're practicing: Generating random numbers and type conversion.\n",
"\n",
"Make your own version of the `Guess a Number` game. Generate a random integer and store it in a variable called `answer`. Print a statement asking the user to guess a number.\n",
"\n",
"If the user's guess is:\n",
"* Higher than the `answer`: print `That is too high!`.\n",
"* Lower than the `answer`: print `That is too low!`.\n",
"* Exactly the `answer`: print `That's it! You win!`.\n",
"\n",
"Your program should keep prompting the user until they enter the correct answer.\n",
"\n",
"#### Example Output\n",
"```\n",
"I'm thinking of a number between 1 and 10.\n",
"Please guess what it is:\n",
"> 4\n",
"That is too low!\n",
"> 8\n",
"That is too high!\n",
"> 6\n",
"That's it! You win!\n",
"```\n",
"\n",
"> **Hint 1:** User input comes to you as a string. How can you make it into an integer so you can properly compare the user's guess with the `answer` (which is an integer)?\n",
"\n",
"> **Hint 2:** You can set a variable to `False` or `True`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "blocked-lottery",
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"\n",
"answer = random.randint(1, 10)\n",
"guessed = False\n",
"\n",
"print(\"I'm thinking of a number between 1 and 10.\")\n",
"\n",
"while not guessed:\n",
" current_guess = int(input(\"Please guess what it is:\"))\n",
"\n",
" if current_guess == answer:\n",
" print(\"That's it! You win!\")\n",
" guessed = True\n",
" elif current_guess < answer:\n",
" print(\"That is too low!\")\n",
" elif current_guess > answer:\n",
" print(\"That is too high!\")"
]
},
{
"cell_type": "markdown",
"id": "static-tuition",
"metadata": {},
"source": [
"---\n",
"## Problem 2: D'oh!\n",
"\n",
"### Skills you're practicing: Using `try`/`except` statements and error handling.\n",
"\n",
"Bart Simpson has gotten ahold of your program from Problem 1 and started entering a bunch of values that are NOT numbers! How do you handle it?\n",
"\n",
"Modify your code from Problem 1 to print `D'oh! That is NOT a number, Bart!` if the user doesn't enter an integer.\n",
"\n",
"#### Example Output\n",
"```\n",
"I'm thinking of a number between 1 and 10.\n",
"Please guess what it is:\n",
"> Eat my shorts!\n",
"D'oh! That is NOT a number, Bart!\n",
"Please guess what it is:\n",
"> Ay, caramba!\n",
"D'oh! That is NOT a number, Bart!\n",
"Please guess what it is:\n",
"> 5\n",
"That is too low!\n",
"Please guess what it is:\n",
"> 8\n",
"That's it! You win!\n",
"```\n",
"\n",
"> **Hint:** The `continue` keyword can be called in a loop and means \"skip the rest of this loop iteration.\" It may be useful to call this in an `except` clause."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "divine-departure",
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"\n",
"answer = random.randint(1, 10)\n",
"guessed = False\n",
"\n",
"print(\"I'm thinking of a number between 1 and 10.\")\n",
"\n",
"while not guessed:\n",
" current_guess = input(\"Please guess what it is:\")\n",
"\n",
" try:\n",
" current_guess = int(current_guess)\n",
" except:\n",
" print(\"D'oh! That is NOT a number, Bart!\")\n",
" continue # This skips the rest of this loop iteration.\n",
"\n",
" if current_guess == answer:\n",
" print(\"That's it! You win!\")\n",
" guessed = True\n",
" elif current_guess < answer:\n",
" print(\"That is too low!\")\n",
" elif current_guess > answer:\n",
" print(\"That is too high!\")"
]
},
{
"cell_type": "markdown",
"id": "floating-victor",
"metadata": {},
"source": [
"---\n",
"## Problem 3:\n",
"\n",
"### Skill you're practicing: Debugging built-in errors.\n",
"\n",
"Fix the errors in the code. Don't change the `rainbow`'s contents.\n",
"\n",
"#### Expected Output\n",
"```\n",
"The rainbow's name is Roy G. Biv\n",
"I'll be taking that gold!\n",
"red\n",
"orange\n",
"yellow\n",
"green\n",
"blue\n",
"What color is indigo?\n",
"violet\n",
"102\n",
"100.0\n",
"```\n",
"\n",
"> **Hint:** You may encounter: `NameError`, `SyntaxError`, `IndentationError`, `KeyError`, `TypeError`, etc. Refer to the class notes for common causes of these errors."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "particular-behavior",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The rainbow's name is Roy G. Biv\n",
"I'll be taking that gold!\n",
"red\n",
"orange\n",
"yellow\n",
"green\n",
"blue\n",
"What color is indigo?\n",
"violet\n",
"102\n",
"100.0\n"
]
}
],
"source": [
"# Fixed Code (You may have some small variations!)\n",
"rainbow = {\n",
" \"name\": \"Roy G. Biv\",\n",
" \"colors\": [\"red\", \"orange\", \"yellow\", \"green\", \"blue\", \"indigo\", \"violet\"],\n",
" \"end\": \"Pot of gold!\",\n",
" \"number\": \"double\",\n",
" \"count\": 2,\n",
" \"gold\": 100\n",
"}\n",
"\n",
"print(\"The rainbow's name is\", rainbow[\"name\"])\n",
"\n",
"if rainbow[\"end\"] == \"Pot of gold!\":\n",
" print(\"I'll be taking that gold!\")\n",
"else:\n",
" print(\"No money for me!\")\n",
"\n",
"for color in rainbow[\"colors\"]:\n",
" if color is not \"indigo\":\n",
" print(color)\n",
" else:\n",
" print(\"What color is indigo?\")\n",
"\n",
"gold_amount = rainbow[\"count\"] + rainbow[\"gold\"]\n",
"print(gold_amount)\n",
"\n",
"persons = 1\n",
"split_gold = rainbow[\"gold\"] / persons\n",
"print(split_gold)"
]
},
{
"cell_type": "markdown",
"id": "perceived-puzzle",
"metadata": {},
"source": [
"---\n",
"## Problem 4: Three Commas\n",
"\n",
"### Skill you're practicing: Formatting numbers.\n",
"\n",
"Russ is a billionaire and he'd like to count his wealth in the number of commas it contains. For example, someone who is a millionaire would have only two commas (1,000,000). Russ, however, has three commas and would like to see those commas displayed. Help Russ format his integer so that commas appear when it is printed out. Make sure your program will work for any value of `wealth`.\n",
"\n",
"#### Example Code\n",
"```python\n",
"wealth = 1000000000\n",
"```\n",
"\n",
"#### Example Output\n",
"```\n",
"1,000,000,000\n",
"```\n",
"\n",
"> **Hint:** Look up `format` if you've forgotten how to use it!"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "indonesian-threat",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1,000,000,000\n"
]
}
],
"source": [
"# We start out with an integer.\n",
"wealth = 1000000000\n",
"\n",
"# We convert it to a string formatted the way we want.\n",
"formatted = format(wealth, ',d')\n",
"\n",
"# Print it out!\n",
"print(formatted)"
]
},
{
"cell_type": "markdown",
"id": "burning-relationship",
"metadata": {},
"source": [
"---\n",
"## Problem 5: My Favorite TV Characters\n",
"\n",
"### Skills you're practicing: Scripting and debugging.\n",
"\n",
"I'm trying to write a list of favorite TV show characters to a file called `my_characters`. I'm nearly there, but instead of printing the whole list, I'm just getting the last line. Help me out: Can you get the whole list to print to a file?\n",
"\n",
"#### My Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "limiting-withdrawal",
"metadata": {},
"outputs": [],
"source": [
"tv_characters = [\"Will Byers\", \"Tyrion Lannister\", \"Oliver Queen\", \"Jean Luc Picard\", \"Malcom Reynolds\", \"The Doctor\", \"Sam Winchester\", \"Sherlock Holmes\"]\n",
"\n",
"# Write out my character list to a file called \"text\"\n",
"for index, character in enumerate(tv_characters):\n",
" f = open(\"text\", \"w\")\n",
" f.write(f\"{index+1}: {character}\\n\")\n",
" f.close()"
]
},
{
"cell_type": "markdown",
"id": "asian-resource",
"metadata": {},
"source": [
"#### Desired Output\n",
"```\n",
"1: Will Byers\n",
"2: Tyrion Lannister\n",
"3: Oliver Queen\n",
"4: Jean-Luc Picard\n",
"5: Malcolm Reynolds\n",
"6: The Doctor\n",
"7: Sam Winchester\n",
"8: Sherlock Holmes\n",
"```\n",
"\n",
"#### Actual Output\n",
"```\n",
"8: Sherlock Holmes\n",
"```\n",
"\n",
"> **Hint:** Remember the [spreadsheet](https://www.dropbox.com/s/cqsxfws52gulkyx/drawing.pdf) we looked at earlier? See if it can help!"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "postal-netherlands",
"metadata": {},
"outputs": [],
"source": [
"tv_characters = [\"Will Byers\", \"Tyrion Lannister\", \"Oliver Queen\", \"Jean-Luc Picard\", \"Malcolm Reynolds\", \"The Doctor\", \"Sam Winchester\", \"Sherlock Holmes\"]\n",
"\n",
"# Open the file outside of the loop.\n",
"f = open(\"my_characters\", \"w\")\n",
"\n",
"for index, character in enumerate(tv_characters):\n",
" f.write(f\"{index+1}: {character}\\n\")\n",
"\n",
"# This happens outside the loop, too.\n",
"f.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fleet-fitness",
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -1,17 +0,0 @@
import random
answer = random.randint(1, 10)
guessed = False
print("I'm thinking of a number between 1 and 10.")
while not guessed:
current_guess = int(input("Please guess what it is:"))
if current_guess == answer:
print("That's it! You win!")
guessed = True
elif current_guess < answer:
print("That is too low!")
elif current_guess > answer:
print("That is too high!")

@ -1,23 +0,0 @@
import random
answer = random.randint(1, 10)
guessed = False
print("I'm thinking of a number between 1 and 10.")
while not guessed:
current_guess = input("Please guess what it is:")
try:
current_guess = int(current_guess)
except:
print("D'oh! That is NOT a number, Bart!")
continue # This skips the rest of this loop iteration.
if current_guess == answer:
print("That's it! You win!")
guessed = True
elif current_guess < answer:
print("That is too low!")
elif current_guess > answer:
print("That is too high!")

@ -1,29 +0,0 @@
# Fixed Code (You may have some small variations!)
rainbow = {
"name": "Roy G. Biv",
"colors": ["red", "orange", "yellow", "green", "blue", "indigo", "violet"],
"end": "Pot of gold!",
"number": "double",
"count": 2,
"gold": 100
}
print("The rainbow's name is", rainbow["name"])
if rainbow["end"] == "Pot of gold!":
print("I'll be taking that gold!")
else:
print("No money for me!")
for color in rainbow["colors"]:
if color is not "indigo":
print(color)
else:
print("What color is indigo?")
gold_amount = rainbow["count"] + rainbow["gold"]
print(gold_amount)
persons = 1
split_gold = rainbow["gold"] / persons
print(split_gold)

@ -1,8 +0,0 @@
# We start out with an integer.
wealth = 1000000000
# We convert it to a string formatted the way we want.
formatted = format(wealth, ',d')
# Print it out!
print(formatted)

@ -1,10 +0,0 @@
tv_characters = ["Will Byers", "Tyrion Lannister", "Oliver Queen", "Jean-Luc Picard", "Malcolm Reynolds", "The Doctor", "Sam Winchester", "Sherlock Holmes"]
# Open the file outside of the loop.
f = open("my_characters", "w")
for index, character in enumerate(tv_characters):
f.write("{0}: {1}\n".format(index+1, character))
# This happens outside the loop, too.
f.close()

@ -0,0 +1,674 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div>\n",
" <span>\n",
" <p align=\"left\">\n",
" <img align=\"left\" style=\"padding-right: 5px\" valign=\"center\" src=\"https://ga-dash.s3.amazonaws.com/production/assets/logo-9f88ae6c9c3871690e33280fcf557f33.png\" width=\"28px\">\n",
" </p>\n",
" </span>\n",
" <span>\n",
" <h1>Consumer Sales Lab</h1>\n",
" </span>\n",
"</div>\n",
"\n",
"<font color='red'><strong>Important!!</font></strong>: This lab is fairly challenging and may take longer than 60m to complete. Because of this, we've included a <a href='#shortcut'>shortcut cell</a> that _skips the EDA section_ of this lab and lets you get right to the analysis section. Work with your instructor and use your best judgement to use your time wisely to focus on the areas you'd like to practice.\n",
"\n",
"This lab can be conducted in one of two ways:\n",
"\n",
"- <a href=\"#eda\">EDA</a> _and_ <a href=\"#analysis\">Analysis</a>\n",
"- <a href=\"#analysis\">Analysis</a> only\n",
"\n",
"The <a href=\"#eda\">EDA</a> section covers the following topics:\n",
"\n",
"- <a href='#import'>Importing</a> data from csvs\n",
"- <a href=\"#nulls\">Handling nulls</a>\n",
"- <a href='#dtypes'>Casting different Dtypes</a>\n",
"- <a href=\"#join\">Complex joining</a> of star-schema tables\n",
"\n",
"The <a href=\"#analysis\">Analysis</a> section covers the following topics:\n",
"\n",
"- <a href='#fe'>Feature engineering</a>\n",
"- <a href=\"#visualization\">Visualization and Reporting</a>\n",
"\n",
"<details>\n",
" <summary>Table of Contents</summary>\n",
" <ul>\n",
" <li><a href=\"#eda\">EDA</a></li>\n",
" <ul>\n",
" <li><a href='#import'>Import</a></li>\n",
" <li><a href=\"#nulls\">Nulls</a></li>\n",
" <li><a href='#dtypes'>Dtypes</a></li>\n",
" <li><a href=\"#join\">Join</a></li>\n",
" </ul>\n",
" <li><a href=\"#analysis\">Analysis</a></li>\n",
" <ul>\n",
" <li><a href='#fe'>Feature Engineering</a></li>\n",
" <li><a href=\"#visualization\">Visualization and Reporting</a></li>\n",
" <ul>\n",
" <li><a href='#1a'>1.A</a></li>\n",
" <li><a href=\"#1b\">1.B</a></li>\n",
" <li><a href='#1c'>1.C</a></li>\n",
" <li><a href=\"#2a\">2.A</a></li>\n",
" <li><a href=\"#3a\">3.A</a></li>\n",
" </ul>\n",
" </ul>\n",
" </ul>\n",
"</details>\n",
"<details>\n",
" <summary>Background</summary>\n",
" <ul>\n",
" <li>Originally adapted from <a href=\"https://sense-demo.qlik.com/sense/app/372cbc85-f7fb-4db6-a620-9a5367845dce\">qlik</a>, we'll be performing EDA on a consumer data set.</li>\n",
" </ul>\n",
"</details>\n",
"<details id='prompts'>\n",
" <summary>Prompts</summary>\n",
" <br>\n",
" Your boss, Joanna, has requested a report on the following:\n",
" <ol>\n",
" <li>Product Sales</li>\n",
" <ol>\n",
" <li>Gross margin analysis by product group.</li>\n",
" <li>Sales by product group, top 10 product groups only.</li>\n",
" <li>Sales, by year/month, year over year</li>\n",
" </ol>\n",
" <li>Sales Reps</li>\n",
" <ol>\n",
" <li>Sum of Sales and sales quantity, by rep, by customer</li>\n",
" </ol>\n",
" <li>Supply Chain</li>\n",
" <ol>\n",
" <li>Inventory vs Lead Time for all products</li>\n",
" </ol>\n",
" </ol>\n",
"</details>\n",
"<details id='dictionary'>\n",
" <summary>Data Dictionary</summary>\n",
" <br>\n",
" <!-- table created with https://www.tablesgenerator.com/html_tables please see ../assets/dictionary.tgn file -->\n",
" <table>\n",
" <tr>\n",
" <th>Table</th>\n",
" <th>Field</th>\n",
" <th>Description</th>\n",
" <th>PK</th>\n",
" <th>FK</th>\n",
" </tr>\n",
" <tr>\n",
" <td>Item master.xls</td>\n",
" <td>Item Number</td>\n",
" <td>Foreign key to Sales.Item Number field. Unique identifier for item</td>\n",
" <td>Y</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Item master.xls</td>\n",
" <td>Product Group</td>\n",
" <td>Group for the product, i.e. Frozen Foods, Deli, etc</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Item master.xls</td>\n",
" <td>Product Line</td>\n",
" <td>Product line, i.e. Food, Drink, etc</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Item master.xls</td>\n",
" <td>Product Sub Group</td>\n",
" <td>Detail field for the Product Group field, i.e. Produce -&gt; Fresh Vegetables</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Item master.xls</td>\n",
" <td>Product Type</td>\n",
" <td>Type of product and additional detail at the sub group level, i.e. 'Breakfast Foods'</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales&nbsp;&nbsp;rep.csv</td>\n",
" <td>Manager</td>\n",
" <td>Name of manager</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr> \n",
" <tr>\n",
" <td>Sales&nbsp;&nbsp;rep.csv</td>\n",
" <td>Manager Number</td>\n",
" <td>ID of manager</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales&nbsp;&nbsp;rep.csv</td>\n",
" <td>Path</td>\n",
" <td>Order through which sales passes through reps, separated by hyphens. Correlates with Sales Rep ID key.</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales&nbsp;&nbsp;rep.csv</td>\n",
" <td>Sales Rep Name</td>\n",
" <td>Primary sales rep name</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales&nbsp;&nbsp;rep.csv</td>\n",
" <td>Sales Rep Name 1</td>\n",
" <td>Secondary sales rep name (nullable)</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales&nbsp;&nbsp;rep.csv</td>\n",
" <td>Sales Rep Name 2</td>\n",
" <td>Tertiary sales rep name (nullable)</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales&nbsp;&nbsp;rep.csv</td>\n",
" <td>Sales Rep Name 3</td>\n",
" <td>Quaterinary sales rep name (nullable)</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales&nbsp;&nbsp;rep.csv</td>\n",
" <td>Sales Rep ID</td>\n",
" <td>Foreign key to Sales. UID for path.</td>\n",
" <td>N</td>\n",
" <td>Y</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Customers.xlsx</td>\n",
" <td>Customer</td>\n",
" <td>Name of customer</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Customers.xlsx</td>\n",
" <td>Customer Number</td>\n",
" <td>Unique identifier for customer name, keys to Sales.Customer Number</td>\n",
" <td>Y</td>\n",
" <td>Y</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Customers.xlsx</td>\n",
" <td>City Code</td>\n",
" <td>City ID, foreign key for City.City Code</td>\n",
" <td>N</td>\n",
" <td>Y</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Cities.xlsx</td>\n",
" <td>City</td>\n",
" <td>Name of city</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Cities.xlsx</td>\n",
" <td>City Code</td>\n",
" <td>ID of city name</td>\n",
" <td>Y</td>\n",
" <td>Y</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Cities.xlsx</td>\n",
" <td>Region</td>\n",
" <td>Sales region (i.e. USA, Nordic, etc)</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Cities.xlsx</td>\n",
" <td>Latitude</td>\n",
" <td>Latitude of city</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Cities.xlsx</td>\n",
" <td>Longitude</td>\n",
" <td>Longitude of city</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Cities.xlsx</td>\n",
" <td>Desc</td>\n",
" <td>String description of city, including city, state (if applicable), and country</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>%KEY</td>\n",
" <td>Primary key of table</td>\n",
" <td>Y</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Cost</td>\n",
" <td>Total cost of sale for transaction [USD]</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Customer Number</td>\n",
" <td>Customer number, keys to Customer.Customer Number</td>\n",
" <td>N</td>\n",
" <td>Y</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Date</td>\n",
" <td>Date of sale</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>GrossSales</td>\n",
" <td>Gross sale for invoice [USD]</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Invoice Date</td>\n",
" <td>Date of invoice</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Item Desc</td>\n",
" <td>Description of invoiced item</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Item Number</td>\n",
" <td>ID of invoiced item (product) - not a primary key. Keys to Item.Item Number</td>\n",
" <td>N</td>\n",
" <td>Y</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Margin</td>\n",
" <td>Percent gross margin of line item sale</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Order Number</td>\n",
" <td>ID of the order placed</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Promised Delivery Date</td>\n",
" <td>Agreed date of delivery</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Sales</td>\n",
" <td>Gross sale for invoice [USD], less cost of sale</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Sales Qty</td>\n",
" <td>Qty of invoiced item sold (see Item Number, Item Desc)</td>\n",
" <td>N</td>\n",
" <td>N</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sales.xlsx</td>\n",
" <td>Sales Rep Number</td>\n",
" <td>Sales rep ID credited with sale</td>\n",
" <td>N</td>\n",
" <td>Y</td>\n",
" </tr>\n",
"</table>\n",
"</details>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='eda'></div>\n",
"<h2>EDA</h2>\n",
"\n",
"Before we create our charts/reports for Joanna, we'll need to sanity check our input data. We'll get to the analysis (feature engineering) and visualization and reporting in just a bit."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='import'></div>\n",
"<h3>Import Data</h3>\n",
"Read in the data. Check the raw file to make sure you understand quote characters, delimiters, and encoding. You will need to use the encoding flag here since we are dealing with international character sets."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Conduct any library imports here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Read in your sales, cities, customers, item_master, and sales_rep csvs here."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='nulls'></div>\n",
"<h3>Nulls</h3>\n",
"Check for nulls and missing values in all imported tables. If you are filling missing values, state your reasoning for dropping and/or imputing data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='dtypes'></div>\n",
"<h3>Dtypes</h3>\n",
"Review all imported tables and convert the data types if necessary, according to the rules in the following table:\n",
"<br><br>\n",
"<table>\n",
" <tr>\n",
" <th>Name</th>\n",
" <th>Dtype</th>\n",
" </tr>\n",
" <tr>\n",
" <td>Primary or Foreign Keys</td>\n",
" <td>int64 or int32</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Currency</td>\n",
" <td>float64</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Text fields</td>\n",
" <td>object (string)</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Discrete, non-negative values</td>\n",
" <td>int64 or int32</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Dates</td>\n",
" <td>datetime64[ns] (Timestamp object)</td>\n",
" </tr>\n",
"</table>\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='join'></div>\n",
"<h3>Join</h3>\n",
"Join all your tables together and store the joined result into a dataframe named <code>cs</code>. You'll need this for the <a href=\"#visualization\">reporting and visualization</a> section below. \n",
"\n",
"Use the <a href=\"#dictionary\">data dictionary</a> for guidance."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='Analysis'></div>\n",
"<h2>Analysis</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='fe'></div>\n",
"<h3>Feature Engineering</h3>\n",
"<ul>\n",
" <li>Create a new column, <code>GrossMargin</code>, which is the <code>GrossSales</code> minus the <code>Cost</code>, all divided by <code>GrossSales</code>. Store this value as a float (percentage).</li>\n",
" <li>Create a new column, <code>ShipDiff</code>, which is the difference between the <code>Promised Delivery Date</code> and the <code>Invoice Date</code>, in <code>seconds</code>.</li>\n",
" <li>Drop the <code>%KEY</code>, <code>Sales Rep Number</code>, <code>Manager Number</code>, <code>Path</code>, <code>Sales Rep ID</code>, and <code>Desc</code>.</li>\n",
"</ul>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='visualization'></div>\n",
"<h2>Reporting and Visualization</h2>\n",
"Create charts or reports according to the <a href=\"#prompts\">prompts</a>.\n",
"\n",
"<b>Use your best judgement to create visualizations or reports to best answer the questions. As yourself questions such as:</b>\n",
"<ul>\n",
" <li>Is the data I'm using categorical or continuous?</li>\n",
" <li>Am I looking at timeseries data?</li>\n",
" <li>Am I representing a part-of-a-whole relationship?</li>\n",
" <li>Do I have many data points? If so, could I report or chart a subset of that data?</li>\n",
"</ul>\n",
"\n",
"<b>There's no right or wrong answer to these questions. As you solve them, focus on this progression:</b>\n",
"<ul>\n",
" <li>First, create a pandas report with a dataframe or list of values that attempts to answer the prompt.</li>\n",
" <li>If you get that done, try charting it out using a pandas charting method, like <code>.plot()</code></li>\n",
" <li>If you get that done, look at how you might make your chart <i>more information dense</i></li>\n",
" <ul>\n",
" <li>Increase chart ink area</li>\n",
" <li>Reduce visual clutter</li>\n",
" <li>Use color to convey meaning</li>\n",
" <li>Increase information density with shape, size, color</li>\n",
" <li>Use callouts to highlight anomalies in your data or points of interest</li>\n",
" </ul>\n",
" <li>If you get that done, look at graduating from the <a href=\"https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html\">pandas plotting methods</a> to <a href=\"https://matplotlib.org/\">matplotlib</a>, which is the backend for pandas plotting. This will allow you more control over your plots but the learning curve is fairly steep. Hang in there!</li>\n",
"</ul>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://cdn.wikimg.net/en/strategywiki/images/7/70/SMB3-warpzone.png\" height=\"150\" width=\"150\">\n",
"\n",
"<div id='shortcut'></div>\n",
"<font color='red'><strong>Shortcut cell</font></strong>: if you'd like to bypass the EDA section, please run the cell below to import a pre-cleaned dataset into variable `cs` for charting purposes:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Shortcut cell\n",
"cs = pd.read_csv('../data/pre_cleaned_data.csv', \n",
" infer_datetime_format=True, \n",
" parse_dates=['Date', 'Invoice Date', 'Promised Delivery Date']\n",
" )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='1a'></div>\n",
"<h3>1.A</h3>\n",
"Gross Margin by product group."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='1b'></div>\n",
"<h3>1.B</h3>\n",
"Sales by product group, top 10 product groups only."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='1c'></div>\n",
"<h3>1.C</h3>\n",
"Sales, by year/month, year over year"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='2a'></div>\n",
"<h3>2.A</h3>\n",
"Sum of Sales and sales quantity, by rep, by customer. Top 10 customer gross sales only. Formatted as a data frame, not a chart."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div id='3a'></div>\n",
"<h3>3.A</h3>\n",
"Scatter plot of mean Gross Margin vs Gross Sales, by Product Sub Group"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A:"
]
}
],
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

@ -0,0 +1,283 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Feature engineering in Pandas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading/Exploring the data\n",
"\n",
"Load the iris.csv file from this repo into a pandas dataframe. Take a minute to familiarize yourself with the data."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import Pandas\n",
"\n",
"Import the `pandas` library as `pd`"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Read the `../data/iris.csv` dataset into an object named `iris`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"How many different species are in this dataset?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What are their names?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"How many samples are there per species?\n",
"\n",
"<details><summary>Hint</summary>Use the <a href=\"http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html\"><code>.value_counts()</code></a> method</details>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Feature Engineering\n",
"\n",
"Create a new column called `'sepal_ratio'` which is equal to sepal width / sepal length"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a similar column called `'petal_ratio'`: petal width / petal length"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create 4 columns that correspond to `sepal length (cm)`, `sepal width (cm)`, `petal length (cm)`, and `petal width (cm)`, only in inches."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Apply\n",
"\n",
"Create a column called `'encoded_species'`:\n",
"- 0 for setosa\n",
"- 1 for versicolor\n",
"- 2 for virginica\n",
"\n",
"\n",
"<details><summary>Hint 1</summary>\n",
"Create a dictionary using the species as keys and the numbers 0-2 for values\n",
"</details>\n",
"\n",
"<details><summary>Hint 2</summary>\n",
" Use the dictionary in hint 1 with the <code>.apply()</code> method to create the new column\n",
"</details>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## March Madness\n",
"\n",
"Let's change up the dataset to something different than flowers: March Madness!\n",
"\n",
"Read in the dataset `../data/ncaa-seeds.csv` to an object named `seeds`.\n",
"\n",
"This dataframe simulates the games that will occur in the first round of the [NCAA basketball tournament](http://www.sportingnews.com/au/ncaa-basketball/news/ncaa-tournament-2017-march-madness-bracket-schedule-matchups-print-a-bracket/1r6cau9sb1xj4131zzhay2dj5g). In the first row, you should see the following:\n",
"\n",
"| team_seed | opponent_seed |\n",
"|-----------|---------------|\n",
"| 01N | 16N |"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For team_seed, the 01 is their seed, and N is their division (North). This row is saying the 1st seed in the north division will play the 16th seed (same division).\n",
"\n",
"Using the `.apply()` method, create the following new columns:\n",
"- `team_division`\n",
"- `opponent_division`\n",
"\n",
"The first row of your result should look as follows:\n",
"\n",
"| team_seed | opponent_seed | team_division | opponent_division |\n",
"|-----------|---------------|---------------|-------------------|\n",
"| 01N | 16N | N | N |\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that you have the divisions, change the `team_seed` and `opponent_seed` columns to just be the numbers.\n",
"\n",
"The first row of your result should look as follows:\n",
"\n",
"| team_seed | opponent_seed | team_division | opponent_division |\n",
"|-----------|---------------|---------------|-------------------|\n",
"| 1 | 16 | N | N |"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a new column called seed_delta, which is the difference between the team's seed and their opponent's. \n",
"\n",
"The first row of your result should look as follows:\n",
"\n",
"| team_seed | opponent_seed | team_division | opponent_division | seed_delta |\n",
"|-----------|---------------|---------------|-------------------|------------|\n",
"| 1 | 16 | N | N | -15 |\n",
"\n",
"<br>\n",
"<details><summary>Did you get an error?</summary>\n",
"team_seed and opponent_seed need to be numerical columns in order for you to perform mathematical operations on them.\n",
"</details>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"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.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading…
Cancel
Save