Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 13. How much was the revenue for the period in the dataset?"
"### Step 13. Turn the item price into a float"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"dollarizer = lambda x: float(x[1:-1])\n",
"chipo.item_price = chipo.item_price.apply(dollarizer)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 14. How much was the revenue for the period in the dataset?"
]
},
{
Expand All @@ -484,28 +503,25 @@
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The revenue of the period was: $34500.16\n"
]
"data": {
"text/plain": [
"34500.16000000046"
]
},
"execution_count": 130,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# create a list of prices\n",
"prices = [float(value[1:-1]) for value in chipo.item_price] # strip the dollar sign and trailing space\n",
"\n",
"total = sum(prices) #sum the items\n",
"\n",
"\n",
"print(\"The revenue of the period was: \" + \"${0:.2f}\".format(total))"
"chipo.item_price.sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 14. How many orders were made in the period?"
"### Step 15. How many orders were made in the period?"
]
},
{
Expand All @@ -527,15 +543,14 @@
}
],
"source": [
"orders = len((set([order for order in chipo.order_id])))\n",
"orders"
"chipo.order_id.value_counts().count()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 15. What is the average amount per order?"
"### Step 16. What is the average amount per order?"
]
},
{
Expand All @@ -546,24 +561,30 @@
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The average order is: $18.81\n"
]
"data": {
"text/plain": [
"18.811428571428689"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"avg_order = total / orders\n",
"order_grouped = chipo.groupby(by=['order_id']).sum()\n",
"order_grouped.mean()['item_price']\n",
"\n",
"# Or \n",
"\n",
"print \"The average order is: $%s\" % round(avg_order, 2)"
"#chipo.groupby(by=['order_id']).sum().mean()['item_price']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 16 How many different items are sold?"
"### Step 17. How many different items are sold?"
]
},
{
Expand All @@ -585,7 +606,7 @@
}
],
"source": [
"len(chipo.item_name.unique())"
"chipo.item_name.value_counts().count()"
]
}
],
Expand Down
24 changes: 20 additions & 4 deletions 01_Getting_&_Knowing_Your_Data/Chipotle/Exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,23 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 13. How much was the revenue for the period in the dataset?"
"### Step 13. Turn the item price into a float"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 14. How much was the revenue for the period in the dataset?"
]
},
{
Expand All @@ -213,7 +229,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 14. How many orders were made in the period?"
"### Step 15. How many orders were made in the period?"
]
},
{
Expand All @@ -229,7 +245,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 15. What is the average amount per order?"
"### Step 16. What is the average amount per order?"
]
},
{
Expand All @@ -245,7 +261,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 16. How many different items are sold?"
"### Step 17. How many different items are sold?"
]
},
{
Expand Down
50 changes: 36 additions & 14 deletions 01_Getting_&_Knowing_Your_Data/Chipotle/Solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,23 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 13. How much was the revenue for the period in the dataset?"
"### Step 13. Turn the item price into a float"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 14. How much was the revenue for the period in the dataset?"
]
},
{
Expand All @@ -452,11 +468,14 @@
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The revenue of the period was: $34500.16\n"
]
"data": {
"text/plain": [
"34500.16000000046"
]
},
"execution_count": 130,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
Expand All @@ -465,7 +484,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 14. How many orders were made in the period?"
"### Step 15. How many orders were made in the period?"
]
},
{
Expand All @@ -492,7 +511,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 15. What is the average amount per order?"
"### Step 16. What is the average amount per order?"
]
},
{
Expand All @@ -503,11 +522,14 @@
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The average order is: $18.81\n"
]
"data": {
"text/plain": [
"18.811428571428689"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
Expand All @@ -516,7 +538,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 16 How many different items are sold?"
"### Step 17. How many different items are sold?"
]
},
{
Expand Down