Skip to content

Commit 4a20bed

Browse files
committed
Revert "fixed solution of visualizing chipo exercise"
This reverts commit beca53e.
1 parent beca53e commit 4a20bed

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

07_Visualization/Chipotle/Solutions.ipynb

+51-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"execution_count": 2,
5151
"metadata": {},
5252
"outputs": [],
53-
"source": []
53+
"source": [
54+
"url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'\n",
55+
" \n",
56+
"chipo = pd.read_csv(url, sep = '\\t')"
57+
]
5458
},
5559
{
5660
"cell_type": "markdown",
@@ -210,7 +214,9 @@
210214
"output_type": "execute_result"
211215
}
212216
],
213-
"source": []
217+
"source": [
218+
"chipo.head(10)"
219+
]
214220
},
215221
{
216222
"cell_type": "markdown",
@@ -237,7 +243,30 @@
237243
"output_type": "display_data"
238244
}
239245
],
240-
"source": []
246+
"source": [
247+
"# get the Series of the names\n",
248+
"x = chipo.item_name\n",
249+
"\n",
250+
"# use the Counter class from collections to create a dictionary with keys(text) and frequency\n",
251+
"letter_counts = Counter(x)\n",
252+
"\n",
253+
"# convert the dictionary to a DataFrame\n",
254+
"df = pd.DataFrame.from_dict(letter_counts, orient='index')\n",
255+
"\n",
256+
"# sort the values from the top to the least value and slice the first 5 items\n",
257+
"df = df[0].sort_values(ascending = True)[45:50]\n",
258+
"\n",
259+
"# create the plot\n",
260+
"df.plot(kind='bar')\n",
261+
"\n",
262+
"# Set the title and labels\n",
263+
"plt.xlabel('Items')\n",
264+
"plt.ylabel('Number of Times Ordered')\n",
265+
"plt.title('Most ordered Chipotle\\'s Items')\n",
266+
"\n",
267+
"# show the plot\n",
268+
"plt.show()"
269+
]
241270
},
242271
{
243272
"cell_type": "markdown",
@@ -275,7 +304,23 @@
275304
"output_type": "display_data"
276305
}
277306
],
278-
"source": []
307+
"source": [
308+
"# create a list of prices\n",
309+
"chipo.item_price = [float(value[1:-1]) for value in chipo.item_price] # strip the dollar sign and trailing space\n",
310+
"\n",
311+
"# then groupby the orders and sum\n",
312+
"orders = chipo.groupby('order_id').sum()\n",
313+
"\n",
314+
"# creates the scatterplot\n",
315+
"# plt.scatter(orders.quantity, orders.item_price, s = 50, c = 'green')\n",
316+
"plt.scatter(x = orders.item_price, y = orders.quantity, s = 50, c = 'green')\n",
317+
"\n",
318+
"# Set the title and labels\n",
319+
"plt.xlabel('Order Price')\n",
320+
"plt.ylabel('Items ordered')\n",
321+
"plt.title('Number of items ordered per order price')\n",
322+
"plt.ylim(0)"
323+
]
279324
},
280325
{
281326
"cell_type": "markdown",
@@ -308,9 +353,9 @@
308353
"name": "python",
309354
"nbconvert_exporter": "python",
310355
"pygments_lexer": "ipython3",
311-
"version": "3.9.1"
356+
"version": "3.6.8"
312357
}
313358
},
314359
"nbformat": 4,
315360
"nbformat_minor": 1
316-
}
361+
}

0 commit comments

Comments
 (0)