Created
April 6, 2020 13:53
-
-
Save zgulde/d2f49756553554f465d6b213f78ea04d to your computer and use it in GitHub Desktop.
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": [ | |
| "# Dataframe Manipulation Warmup" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import numpy as np\n", | |
| "import pandas as pd\n", | |
| "\n", | |
| "np.random.seed(406)\n", | |
| "\n", | |
| "n = 5000\n", | |
| "df = pd.DataFrame({\n", | |
| " 'favorite_animal': np.random.choice(['cat', 'dog', 'frog', 'lemur', 'panda'], n),\n", | |
| " 'favorite_vegetable': np.random.choice(['brussel sprouts', 'potato', 'squash'], n),\n", | |
| " 'favorite_fruit': np.random.choice(['banana', 'apple', 'blueberries'], n),\n", | |
| " 'wears_glasses': np.random.choice(['yes', 'no'], n),\n", | |
| " 'netflix_consumption': np.random.normal(10, 2, n),\n", | |
| " 'open_browser_tabs': np.random.randint(2, 90, n),\n", | |
| "})" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "- What is the highest amount of netflix consumption? `17.535`\n", | |
| "- How many people wear glasses? What percentage of people is this? `2555`, `.511`\n", | |
| "- How many people's favorite animal is a dog? `1002`\n", | |
| "- What is the most common favorite animal? `lemur`\n", | |
| "- What is the average netflix consumption for people that prefer brussel\n", | |
| " sprouts? `10.008`\n", | |
| "- What is the most common favorite fruit for people who wear glasses and have\n", | |
| " more than 40 open browser tabs? `blueberries`\n", | |
| "- What percentage of people have a netflix consumption lower than 7? `.0716`\n", | |
| "- What is the average netflix consumption for people with less than 30 open\n", | |
| " browser tabs? `9.91935`\n", | |
| "- How many people *don't* wear glasses, have a favorite animal of a panda, have\n", | |
| " a favorite fruit of blueberries, and have more than 60 open browser tabs? What\n", | |
| " is the median netflix consumption for this group? What is the most common\n", | |
| " favorite vegetable for this group? `46`, `10.455`, `potato`\n", | |
| "- What is the least popular combination of favorite fruit and vegetable? `apple` and `potato`\n", | |
| "- Which combination of favorite animal and wearing glasses has the highest average\n", | |
| " netflix consumption? people that wear glasses and prefer pandas\n", | |
| "- **Bonus**: for each of the above questions, what kind of visualization would\n", | |
| " be the most effective in conveying your answer?" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.7.3" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment