Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the visualising chipo solution #1

Merged
merged 6 commits into from
Mar 20, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
fixed visualising chipo exercise
  • Loading branch information
CinnamonXI committed Mar 20, 2021

Verified

This commit was signed with the committer’s verified signature.
winchesHe winches
commit afe9e2e2c6ff716a20b0b7a69e8db8839d7faec3
57 changes: 6 additions & 51 deletions 07_Visualization/Chipotle/Solutions.ipynb
Original file line number Diff line number Diff line change
@@ -50,11 +50,7 @@
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'\n",
" \n",
"chipo = pd.read_csv(url, sep = '\\t')"
]
"source": []
},
{
"cell_type": "markdown",
@@ -214,9 +210,7 @@
"output_type": "execute_result"
}
],
"source": [
"chipo.head(10)"
]
"source": []
},
{
"cell_type": "markdown",
@@ -243,30 +237,7 @@
"output_type": "display_data"
}
],
"source": [
"# get the Series of the names\n",
"x = chipo.item_name\n",
"\n",
"# use the Counter class from collections to create a dictionary with keys(text) and frequency\n",
"letter_counts = Counter(x)\n",
"\n",
"# convert the dictionary to a DataFrame\n",
"df = pd.DataFrame.from_dict(letter_counts, orient='index')\n",
"\n",
"# sort the values from the top to the least value and slice the first 5 items\n",
"df = df[0].sort_values(ascending = True)[45:50]\n",
"\n",
"# create the plot\n",
"df.plot(kind='bar')\n",
"\n",
"# Set the title and labels\n",
"plt.xlabel('Items')\n",
"plt.ylabel('Number of Times Ordered')\n",
"plt.title('Most ordered Chipotle\\'s Items')\n",
"\n",
"# show the plot\n",
"plt.show()"
]
"source": []
},
{
"cell_type": "markdown",
@@ -304,23 +275,7 @@
"output_type": "display_data"
}
],
"source": [
"# create a list of prices\n",
"chipo.item_price = [float(value[1:-1]) for value in chipo.item_price] # strip the dollar sign and trailing space\n",
"\n",
"# then groupby the orders and sum\n",
"orders = chipo.groupby('order_id').sum()\n",
"\n",
"# creates the scatterplot\n",
"# plt.scatter(orders.quantity, orders.item_price, s = 50, c = 'green')\n",
"plt.scatter(x = orders.item_price, y = orders.quantity, s = 50, c = 'green')\n",
"\n",
"# Set the title and labels\n",
"plt.xlabel('Order Price')\n",
"plt.ylabel('Items ordered')\n",
"plt.title('Number of items ordered per order price')\n",
"plt.ylim(0)"
]
"source": []
},
{
"cell_type": "markdown",
@@ -353,9 +308,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
}