Skip to content

Commit 3da2d91

Browse files
committed
fixed chipotle exercise
1 parent 508c789 commit 3da2d91

File tree

3 files changed

+245
-108
lines changed

3 files changed

+245
-108
lines changed

01_Getting_&_Knowing_Your_Data/Chipotle/Exercise_with_Solutions.ipynb

Lines changed: 129 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
},
2020
{
2121
"cell_type": "code",
22-
"execution_count": 5,
22+
"execution_count": 25,
2323
"metadata": {
2424
"collapsed": false
2525
},
2626
"outputs": [],
2727
"source": [
28-
"import pandas as pd"
28+
"import pandas as pd\n",
29+
"import numpy as np"
2930
]
3031
},
3132
{
@@ -44,7 +45,7 @@
4445
},
4546
{
4647
"cell_type": "code",
47-
"execution_count": 6,
48+
"execution_count": 3,
4849
"metadata": {
4950
"collapsed": false
5051
},
@@ -64,7 +65,7 @@
6465
},
6566
{
6667
"cell_type": "code",
67-
"execution_count": 32,
68+
"execution_count": 4,
6869
"metadata": {
6970
"collapsed": false,
7071
"scrolled": false
@@ -196,7 +197,7 @@
196197
"9 [Fresh Tomato Salsa, [Rice, Black Beans, Pinto... $9.25 "
197198
]
198199
},
199-
"execution_count": 32,
200+
"execution_count": 4,
200201
"metadata": {},
201202
"output_type": "execute_result"
202203
}
@@ -215,7 +216,7 @@
215216
},
216217
{
217218
"cell_type": "code",
218-
"execution_count": 111,
219+
"execution_count": 5,
219220
"metadata": {
220221
"collapsed": false
221222
},
@@ -242,7 +243,7 @@
242243
"4622"
243244
]
244245
},
245-
"execution_count": 111,
246+
"execution_count": 5,
246247
"metadata": {},
247248
"output_type": "execute_result"
248249
}
@@ -265,7 +266,7 @@
265266
},
266267
{
267268
"cell_type": "code",
268-
"execution_count": 109,
269+
"execution_count": 6,
269270
"metadata": {
270271
"collapsed": false
271272
},
@@ -276,7 +277,7 @@
276277
"5"
277278
]
278279
},
279-
"execution_count": 109,
280+
"execution_count": 6,
280281
"metadata": {},
281282
"output_type": "execute_result"
282283
}
@@ -294,7 +295,7 @@
294295
},
295296
{
296297
"cell_type": "code",
297-
"execution_count": 9,
298+
"execution_count": 7,
298299
"metadata": {
299300
"collapsed": false
300301
},
@@ -307,7 +308,7 @@
307308
" dtype='object')"
308309
]
309310
},
310-
"execution_count": 9,
311+
"execution_count": 7,
311312
"metadata": {},
312313
"output_type": "execute_result"
313314
}
@@ -325,7 +326,7 @@
325326
},
326327
{
327328
"cell_type": "code",
328-
"execution_count": 10,
329+
"execution_count": 8,
329330
"metadata": {
330331
"collapsed": false
331332
},
@@ -336,7 +337,7 @@
336337
"RangeIndex(start=0, stop=4622, step=1)"
337338
]
338339
},
339-
"execution_count": 10,
340+
"execution_count": 8,
340341
"metadata": {},
341342
"output_type": "execute_result"
342343
}
@@ -354,27 +355,53 @@
354355
},
355356
{
356357
"cell_type": "code",
357-
"execution_count": 139,
358+
"execution_count": 41,
358359
"metadata": {
359360
"collapsed": false
360361
},
361362
"outputs": [
362363
{
363364
"data": {
365+
"text/html": [
366+
"<div>\n",
367+
"<table border=\"1\" class=\"dataframe\">\n",
368+
" <thead>\n",
369+
" <tr style=\"text-align: right;\">\n",
370+
" <th></th>\n",
371+
" <th>order_id</th>\n",
372+
" <th>quantity</th>\n",
373+
" </tr>\n",
374+
" <tr>\n",
375+
" <th>item_name</th>\n",
376+
" <th></th>\n",
377+
" <th></th>\n",
378+
" </tr>\n",
379+
" </thead>\n",
380+
" <tbody>\n",
381+
" <tr>\n",
382+
" <th>Chicken Bowl</th>\n",
383+
" <td>713926</td>\n",
384+
" <td>761</td>\n",
385+
" </tr>\n",
386+
" </tbody>\n",
387+
"</table>\n",
388+
"</div>"
389+
],
364390
"text/plain": [
365-
"Chicken Bowl 761\n",
366-
"*Don't forget to include the quantity in your calculations!"
391+
" order_id quantity\n",
392+
"item_name \n",
393+
"Chicken Bowl 713926 761"
367394
]
368395
},
369-
"execution_count": 139,
396+
"execution_count": 41,
370397
"metadata": {},
371398
"output_type": "execute_result"
372399
}
373400
],
374401
"source": [
375-
"c = chipo.groupby('item_name')",
376-
"c = c.sum()",
377-
"c = c.sort_values(['quantity'], ascending=False)",
402+
"c = chipo.groupby('item_name')\n",
403+
"c = c.sum()\n",
404+
"c = c.sort_values(['quantity'], ascending=False)\n",
378405
"c.head(1)"
379406
]
380407
},
@@ -387,28 +414,55 @@
387414
},
388415
{
389416
"cell_type": "code",
390-
"execution_count": 93,
417+
"execution_count": 21,
391418
"metadata": {
392419
"collapsed": false
393420
},
394421
"outputs": [
395422
{
396423
"data": {
424+
"text/html": [
425+
"<div>\n",
426+
"<table border=\"1\" class=\"dataframe\">\n",
427+
" <thead>\n",
428+
" <tr style=\"text-align: right;\">\n",
429+
" <th></th>\n",
430+
" <th>order_id</th>\n",
431+
" <th>quantity</th>\n",
432+
" </tr>\n",
433+
" <tr>\n",
434+
" <th>item_name</th>\n",
435+
" <th></th>\n",
436+
" <th></th>\n",
437+
" </tr>\n",
438+
" </thead>\n",
439+
" <tbody>\n",
440+
" <tr>\n",
441+
" <th>Chicken Bowl</th>\n",
442+
" <td>713926</td>\n",
443+
" <td>761</td>\n",
444+
" </tr>\n",
445+
" </tbody>\n",
446+
"</table>\n",
447+
"</div>"
448+
],
397449
"text/plain": [
398-
"761"
450+
" order_id quantity\n",
451+
"item_name \n",
452+
"Chicken Bowl 713926 761"
399453
]
400454
},
401-
"execution_count": 93,
455+
"execution_count": 21,
402456
"metadata": {},
403457
"output_type": "execute_result"
404458
}
405459
],
406460
"source": [
407-
"c = chipo.groupby('item_name')",
408-
"c = c.sum()",
409-
"c = c.sort_values(['quantity'], ascending=False)",
461+
"c = chipo.groupby('item_name')\n",
462+
"c = c.sum()\n",
463+
"c = c.sort_values(['quantity'], ascending=False)\n",
410464
"c.head(1)"
411-
]
465+
]
412466
},
413467
{
414468
"cell_type": "markdown",
@@ -419,32 +473,54 @@
419473
},
420474
{
421475
"cell_type": "code",
422-
"execution_count": 12,
476+
"execution_count": 23,
423477
"metadata": {
424478
"collapsed": false
425479
},
426480
"outputs": [
427481
{
428482
"data": {
483+
"text/html": [
484+
"<div>\n",
485+
"<table border=\"1\" class=\"dataframe\">\n",
486+
" <thead>\n",
487+
" <tr style=\"text-align: right;\">\n",
488+
" <th></th>\n",
489+
" <th>order_id</th>\n",
490+
" <th>quantity</th>\n",
491+
" </tr>\n",
492+
" <tr>\n",
493+
" <th>choice_description</th>\n",
494+
" <th></th>\n",
495+
" <th></th>\n",
496+
" </tr>\n",
497+
" </thead>\n",
498+
" <tbody>\n",
499+
" <tr>\n",
500+
" <th>[Diet Coke]</th>\n",
501+
" <td>123455</td>\n",
502+
" <td>159</td>\n",
503+
" </tr>\n",
504+
" </tbody>\n",
505+
"</table>\n",
506+
"</div>"
507+
],
429508
"text/plain": [
430-
"[Diet Coke] 159\n",
431-
"[Coke] 143\n",
432-
"[Sprite] 89\n",
433-
"[Fresh Tomato Salsa, [Rice, Black Beans, Cheese, Sour Cream, Lettuce]] 49\n",
434-
"[Fresh Tomato Salsa, [Rice, Black Beans, Cheese, Sour Cream]] 42\n",
435-
"Name: choice_description, dtype: int64"
509+
" order_id quantity\n",
510+
"choice_description \n",
511+
"[Diet Coke] 123455 159"
436512
]
437513
},
438-
"execution_count": 12,
514+
"execution_count": 23,
439515
"metadata": {},
440516
"output_type": "execute_result"
441517
}
442518
],
443519
"source": [
444-
"c = chipo.groupby('choice_description').sum()",
445-
"c = c.sort_values(['quantity'], ascending=False)",
446-
"c.head(1)",
447-
"Diet Coke 159"
520+
"c = chipo.groupby('choice_description').sum()\n",
521+
"c = c.sort_values(['quantity'], ascending=False)\n",
522+
"c.head(1)\n",
523+
"# Diet Coke 159"
448524
]
449525
},
450526
{
@@ -456,7 +532,7 @@
456532
},
457533
{
458534
"cell_type": "code",
459-
"execution_count": 9,
535+
"execution_count": 42,
460536
"metadata": {
461537
"collapsed": false
462538
},
@@ -467,7 +543,7 @@
467543
"4972"
468544
]
469545
},
470-
"execution_count": 9,
546+
"execution_count": 42,
471547
"metadata": {},
472548
"output_type": "execute_result"
473549
}
@@ -486,7 +562,7 @@
486562
},
487563
{
488564
"cell_type": "code",
489-
"execution_count": null,
565+
"execution_count": 43,
490566
"metadata": {
491567
"collapsed": true
492568
},
@@ -505,24 +581,23 @@
505581
},
506582
{
507583
"cell_type": "code",
508-
"execution_count": 122,
584+
"execution_count": 47,
509585
"metadata": {
510586
"collapsed": false
511587
},
512588
"outputs": [
513589
{
514-
"data": {
515-
"text/plain": [
516-
"34500.16000000046"
517-
]
518-
},
519-
"execution_count": 130,
520-
"metadata": {},
521-
"output_type": "execute_result"
590+
"name": "stdout",
591+
"output_type": "stream",
592+
"text": [
593+
"Revenue was: $39237.02\n"
594+
]
522595
}
523596
],
524597
"source": [
525-
"chipo.item_price.sum()"
598+
"revenue = (chipo['quantity']* chipo['item_price']).sum()\n",
599+
"\n",
600+
"print('Revenue was: $' + str(np.round(revenue,2)))"
526601
]
527602
},
528603
{
@@ -619,22 +694,11 @@
619694
}
620695
],
621696
"metadata": {
697+
"anaconda-cloud": {},
622698
"kernelspec": {
623-
"display_name": "Python 2",
699+
"display_name": "Python [default]",
624700
"language": "python",
625701
"name": "python2"
626-
},
627-
"language_info": {
628-
"codemirror_mode": {
629-
"name": "ipython",
630-
"version": 2
631-
},
632-
"file_extension": ".py",
633-
"mimetype": "text/x-python",
634-
"name": "python",
635-
"nbconvert_exporter": "python",
636-
"pygments_lexer": "ipython2",
637-
"version": "2.7.11"
638702
}
639703
},
640704
"nbformat": 4,

0 commit comments

Comments
 (0)