Skip to content

Instantly share code, notes, and snippets.

@tabrez
Created December 11, 2017 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabrez/30ee9b1811a5399344174c685a1d7365 to your computer and use it in GitHub Desktop.
Save tabrez/30ee9b1811a5399344174c685a1d7365 to your computer and use it in GitHub Desktop.
My_solutions.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Getting and Knowing your Data"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "This time we are going to pull data directly from the internet.\nSpecial thanks to: https://github.com/justmarkham for sharing the dataset and materials.\n\n### Step 1. Import the necessary libraries"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 1,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 2. Import the dataset from this [address](https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv). "
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 3. Assign it to a variable called chipo."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 2,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 4. See the first 10 entries"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 3,
"data": {
"text/plain": " order_id quantity item_name \\\n0 1 1 Chips and Fresh Tomato Salsa \n1 1 1 Izze \n2 1 1 Nantucket Nectar \n3 1 1 Chips and Tomatillo-Green Chili Salsa \n4 2 2 Chicken Bowl \n5 3 1 Chicken Bowl \n6 3 1 Side of Chips \n7 4 1 Steak Burrito \n8 4 1 Steak Soft Tacos \n9 5 1 Steak Burrito \n\n choice_description item_price \n0 NaN $2.39 \n1 [Clementine] $3.39 \n2 [Apple] $3.39 \n3 NaN $2.39 \n4 [Tomatillo-Red Chili Salsa (Hot), [Black Beans... $16.98 \n5 [Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou... $10.98 \n6 NaN $1.69 \n7 [Tomatillo Red Chili Salsa, [Fajita Vegetables... $11.75 \n8 [Tomatillo Green Chili Salsa, [Pinto Beans, Ch... $9.25 \n9 [Fresh Tomato Salsa, [Rice, Black Beans, Pinto... $9.25 ",
"text/html": "<div>\n<style>\n .dataframe thead tr:only-child th {\n text-align: right;\n }\n\n .dataframe thead th {\n text-align: left;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>order_id</th>\n <th>quantity</th>\n <th>item_name</th>\n <th>choice_description</th>\n <th>item_price</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>1</td>\n <td>Chips and Fresh Tomato Salsa</td>\n <td>NaN</td>\n <td>$2.39</td>\n </tr>\n <tr>\n <th>1</th>\n <td>1</td>\n <td>1</td>\n <td>Izze</td>\n <td>[Clementine]</td>\n <td>$3.39</td>\n </tr>\n <tr>\n <th>2</th>\n <td>1</td>\n <td>1</td>\n <td>Nantucket Nectar</td>\n <td>[Apple]</td>\n <td>$3.39</td>\n </tr>\n <tr>\n <th>3</th>\n <td>1</td>\n <td>1</td>\n <td>Chips and Tomatillo-Green Chili Salsa</td>\n <td>NaN</td>\n <td>$2.39</td>\n </tr>\n <tr>\n <th>4</th>\n <td>2</td>\n <td>2</td>\n <td>Chicken Bowl</td>\n <td>[Tomatillo-Red Chili Salsa (Hot), [Black Beans...</td>\n <td>$16.98</td>\n </tr>\n <tr>\n <th>5</th>\n <td>3</td>\n <td>1</td>\n <td>Chicken Bowl</td>\n <td>[Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou...</td>\n <td>$10.98</td>\n </tr>\n <tr>\n <th>6</th>\n <td>3</td>\n <td>1</td>\n <td>Side of Chips</td>\n <td>NaN</td>\n <td>$1.69</td>\n </tr>\n <tr>\n <th>7</th>\n <td>4</td>\n <td>1</td>\n <td>Steak Burrito</td>\n <td>[Tomatillo Red Chili Salsa, [Fajita Vegetables...</td>\n <td>$11.75</td>\n </tr>\n <tr>\n <th>8</th>\n <td>4</td>\n <td>1</td>\n <td>Steak Soft Tacos</td>\n <td>[Tomatillo Green Chili Salsa, [Pinto Beans, Ch...</td>\n <td>$9.25</td>\n </tr>\n <tr>\n <th>9</th>\n <td>5</td>\n <td>1</td>\n <td>Steak Burrito</td>\n <td>[Fresh Tomato Salsa, [Rice, Black Beans, Pinto...</td>\n <td>$9.25</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 5. What is the number of observations in the dataset?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 4,
"data": {
"text/plain": "4622"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 6. What is the number of columns in the dataset?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 5,
"data": {
"text/plain": "5"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 7. Print the name of all the columns."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 6,
"data": {
"text/plain": "Index(['order_id', 'quantity', 'item_name', 'choice_description',\n 'item_price'],\n dtype='object')"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 8. How is the dataset indexed?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 7,
"data": {
"text/plain": "RangeIndex(start=0, stop=4622, step=1)"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 9. Which was the most ordered item?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 8,
"data": {
"text/plain": "'Chicken Bowl'"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 10. How many items were ordered?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 9,
"data": {
"text/plain": "50"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 11. What was the most ordered item in the choice_description column?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 10,
"data": {
"text/plain": "'[Diet Coke]'"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 12. How many items were orderd in total?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 11,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 11,
"data": {
"text/plain": "4972"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 13. Turn the item price into a float"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 12,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 12,
"data": {
"text/plain": "0 2.39\n1 3.39\n2 3.39\n3 2.39\n4 16.98\nName: item_price, dtype: float64"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 14. How much was the revenue for the period in the dataset?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 13,
"data": {
"text/plain": "'$39237.020000000055'"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 15. How many orders were made in the period?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 14,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 14,
"data": {
"text/plain": "1834"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 16. What is the average amount per order?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 15,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 15,
"data": {
"text/plain": "21.3942311886587"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Step 17. How many different items are sold?"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 16,
"data": {
"text/plain": "50"
},
"metadata": {}
}
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.3",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "My_solutions.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment