You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Data-Science-For-Beginners/3-Data-Visualization/11-visualization-proportions/solution/notebook.ipynb

1300 lines
153 KiB

{
"cells": [
{
"cell_type": "markdown",
"source": [
"# 🍄 Mushroom Proportions"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"Import the mushroom dataset"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 4,
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"mushrooms = pd.read_csv('../../../data/mushrooms.csv')\n",
"mushrooms.head()"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" class cap-shape cap-surface cap-color bruises odor \\\n",
"0 Poisonous Convex Smooth Brown Bruises Pungent \n",
"1 Edible Convex Smooth Yellow Bruises Almond \n",
"2 Edible Bell Smooth White Bruises Anise \n",
"3 Poisonous Convex Scaly White Bruises Pungent \n",
"4 Edible Convex Smooth Green No Bruises None \n",
"\n",
" gill-attachment gill-spacing gill-size gill-color ... \\\n",
"0 Free Close Narrow Black ... \n",
"1 Free Close Broad Black ... \n",
"2 Free Close Broad Brown ... \n",
"3 Free Close Narrow Brown ... \n",
"4 Free Crowded Broad Black ... \n",
"\n",
" stalk-surface-below-ring stalk-color-above-ring stalk-color-below-ring \\\n",
"0 Smooth White White \n",
"1 Smooth White White \n",
"2 Smooth White White \n",
"3 Smooth White White \n",
"4 Smooth White White \n",
"\n",
" veil-type veil-color ring-number ring-type spore-print-color population \\\n",
"0 Partial White One Pendant Black Scattered \n",
"1 Partial White One Pendant Brown Numerous \n",
"2 Partial White One Pendant Brown Numerous \n",
"3 Partial White One Pendant Black Scattered \n",
"4 Partial White One Evanescent Brown Abundant \n",
"\n",
" habitat \n",
"0 Urban \n",
"1 Grasses \n",
"2 Meadows \n",
"3 Urban \n",
"4 Grasses \n",
"\n",
"[5 rows x 23 columns]"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>class</th>\n",
" <th>cap-shape</th>\n",
" <th>cap-surface</th>\n",
" <th>cap-color</th>\n",
" <th>bruises</th>\n",
" <th>odor</th>\n",
" <th>gill-attachment</th>\n",
" <th>gill-spacing</th>\n",
" <th>gill-size</th>\n",
" <th>gill-color</th>\n",
" <th>...</th>\n",
" <th>stalk-surface-below-ring</th>\n",
" <th>stalk-color-above-ring</th>\n",
" <th>stalk-color-below-ring</th>\n",
" <th>veil-type</th>\n",
" <th>veil-color</th>\n",
" <th>ring-number</th>\n",
" <th>ring-type</th>\n",
" <th>spore-print-color</th>\n",
" <th>population</th>\n",
" <th>habitat</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Poisonous</td>\n",
" <td>Convex</td>\n",
" <td>Smooth</td>\n",
" <td>Brown</td>\n",
" <td>Bruises</td>\n",
" <td>Pungent</td>\n",
" <td>Free</td>\n",
" <td>Close</td>\n",
" <td>Narrow</td>\n",
" <td>Black</td>\n",
" <td>...</td>\n",
" <td>Smooth</td>\n",
" <td>White</td>\n",
" <td>White</td>\n",
" <td>Partial</td>\n",
" <td>White</td>\n",
" <td>One</td>\n",
" <td>Pendant</td>\n",
" <td>Black</td>\n",
" <td>Scattered</td>\n",
" <td>Urban</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Edible</td>\n",
" <td>Convex</td>\n",
" <td>Smooth</td>\n",
" <td>Yellow</td>\n",
" <td>Bruises</td>\n",
" <td>Almond</td>\n",
" <td>Free</td>\n",
" <td>Close</td>\n",
" <td>Broad</td>\n",
" <td>Black</td>\n",
" <td>...</td>\n",
" <td>Smooth</td>\n",
" <td>White</td>\n",
" <td>White</td>\n",
" <td>Partial</td>\n",
" <td>White</td>\n",
" <td>One</td>\n",
" <td>Pendant</td>\n",
" <td>Brown</td>\n",
" <td>Numerous</td>\n",
" <td>Grasses</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Edible</td>\n",
" <td>Bell</td>\n",
" <td>Smooth</td>\n",
" <td>White</td>\n",
" <td>Bruises</td>\n",
" <td>Anise</td>\n",
" <td>Free</td>\n",
" <td>Close</td>\n",
" <td>Broad</td>\n",
" <td>Brown</td>\n",
" <td>...</td>\n",
" <td>Smooth</td>\n",
" <td>White</td>\n",
" <td>White</td>\n",
" <td>Partial</td>\n",
" <td>White</td>\n",
" <td>One</td>\n",
" <td>Pendant</td>\n",
" <td>Brown</td>\n",
" <td>Numerous</td>\n",
" <td>Meadows</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Poisonous</td>\n",
" <td>Convex</td>\n",
" <td>Scaly</td>\n",
" <td>White</td>\n",
" <td>Bruises</td>\n",
" <td>Pungent</td>\n",
" <td>Free</td>\n",
" <td>Close</td>\n",
" <td>Narrow</td>\n",
" <td>Brown</td>\n",
" <td>...</td>\n",
" <td>Smooth</td>\n",
" <td>White</td>\n",
" <td>White</td>\n",
" <td>Partial</td>\n",
" <td>White</td>\n",
" <td>One</td>\n",
" <td>Pendant</td>\n",
" <td>Black</td>\n",
" <td>Scattered</td>\n",
" <td>Urban</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Edible</td>\n",
" <td>Convex</td>\n",
" <td>Smooth</td>\n",
" <td>Green</td>\n",
" <td>No Bruises</td>\n",
" <td>None</td>\n",
" <td>Free</td>\n",
" <td>Crowded</td>\n",
" <td>Broad</td>\n",
" <td>Black</td>\n",
" <td>...</td>\n",
" <td>Smooth</td>\n",
" <td>White</td>\n",
" <td>White</td>\n",
" <td>Partial</td>\n",
" <td>White</td>\n",
" <td>One</td>\n",
" <td>Evanescent</td>\n",
" <td>Brown</td>\n",
" <td>Abundant</td>\n",
" <td>Grasses</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 23 columns</p>\n",
"</div>"
]
},
"metadata": {},
"execution_count": 4
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Pie chart\n",
"\n",
"Create a pie chart displaying the proportion of Poisonous vs. Edible mushrooms"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 5,
"source": [
"print(mushrooms.select_dtypes([\"object\"]).columns)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Index(['class', 'cap-shape', 'cap-surface', 'cap-color', 'bruises', 'odor',\n",
" 'gill-attachment', 'gill-spacing', 'gill-size', 'gill-color',\n",
" 'stalk-shape', 'stalk-root', 'stalk-surface-above-ring',\n",
" 'stalk-surface-below-ring', 'stalk-color-above-ring',\n",
" 'stalk-color-below-ring', 'veil-type', 'veil-color', 'ring-number',\n",
" 'ring-type', 'spore-print-color', 'population', 'habitat'],\n",
" dtype='object')\n"
]
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 6,
"source": [
"cols = mushrooms.select_dtypes([\"object\"]).columns\n",
"mushrooms[cols] = mushrooms[cols].astype('category')"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 7,
"source": [
"edibleclass=mushrooms.groupby(['class']).count()\n",
"edibleclass"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" cap-shape cap-surface cap-color bruises odor gill-attachment \\\n",
"class \n",
"Edible 4208 4208 4208 4208 4208 4208 \n",
"Poisonous 3916 3916 3916 3916 3916 3916 \n",
"\n",
" gill-spacing gill-size gill-color stalk-shape ... \\\n",
"class ... \n",
"Edible 4208 4208 4208 4208 ... \n",
"Poisonous 3916 3916 3916 3916 ... \n",
"\n",
" stalk-surface-below-ring stalk-color-above-ring \\\n",
"class \n",
"Edible 4208 4208 \n",
"Poisonous 3916 3916 \n",
"\n",
" stalk-color-below-ring veil-type veil-color ring-number \\\n",
"class \n",
"Edible 4208 4208 4208 4208 \n",
"Poisonous 3916 3916 3916 3916 \n",
"\n",
" ring-type spore-print-color population habitat \n",
"class \n",
"Edible 4208 4208 4208 4208 \n",
"Poisonous 3916 3916 3916 3916 \n",
"\n",
"[2 rows x 22 columns]"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>cap-shape</th>\n",
" <th>cap-surface</th>\n",
" <th>cap-color</th>\n",
" <th>bruises</th>\n",
" <th>odor</th>\n",
" <th>gill-attachment</th>\n",
" <th>gill-spacing</th>\n",
" <th>gill-size</th>\n",
" <th>gill-color</th>\n",
" <th>stalk-shape</th>\n",
" <th>...</th>\n",
" <th>stalk-surface-below-ring</th>\n",
" <th>stalk-color-above-ring</th>\n",
" <th>stalk-color-below-ring</th>\n",
" <th>veil-type</th>\n",
" <th>veil-color</th>\n",
" <th>ring-number</th>\n",
" <th>ring-type</th>\n",
" <th>spore-print-color</th>\n",
" <th>population</th>\n",
" <th>habitat</th>\n",
" </tr>\n",
" <tr>\n",
" <th>class</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Edible</th>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>...</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" <td>4208</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Poisonous</th>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>...</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" <td>3916</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>2 rows × 22 columns</p>\n",
"</div>"
]
},
"metadata": {},
"execution_count": 7
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 8,
"source": [
"labels=['Edible','Poisonous']\n",
"plt.pie(edibleclass['population'],labels=labels,autopct='%.1f %%')\n",
"plt.title('Edible?')\n",
"plt.show()"
],
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAAD3CAYAAADmIkO7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAaH0lEQVR4n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+71NqaUUV42jqKIKKSoO3r9uWY/Lt9SuwhhDyZj9aVj+DDWz47Rt30jrtoIe8G468EPbRQxU3oUTuJoC2s9MtzSRbm545/umNa9QWjOp3+8vHllDy/oVpFubMMbQ9O9XKdmn5+NjOxbfzagPfhbSbWDSwYsimLbmvVqPPHBFNJ481XYRA5FXm7XRePK9wMsU0PCVrTs2svmhG4Mn6TTD3/shqj4QDJnTsPJZti24i/ZGn0jZCErHTmbcp2+gbddWtj52G+PO/g4AOxbfQ/3yxUgkQum4KexzypVI8Z53yDWs/D9aNq1m1PHnAbD9qV/RuOZlSsZGqZl1bW5W2K6NwGGpRGyL7UL6I2/CmZlM6DngKNu1qLz251QidobtIvojnzZrv4kGU+292Zn7fJ2XFz1nNJ6cSTC4U0GflFM5sx2YmkrEttkupDf50nPeigZTZc9ogrlWneZ8zxmNJ2cBD9uuQxWcFuC9qURsle1CeuJ0zxmNJ4uAhO06VEEqBb5nu4jeOB1O4PMEQ/IrNRTOdHmITWc3a6PxZDnwBrCf7VpUQXseODaViDkXBJd7zqvQYKqhdwzg5ERJTvac0XhyH2AVUGW7FhUKKWB6KhFrtV1IZ672nHE0mCp3osA5tovoyrlwRuP
},
"metadata": {}
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 9,
"source": [
"capcolor=mushrooms.groupby(['cap-color']).count()\n",
"capcolor"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" class cap-shape cap-surface bruises odor gill-attachment \\\n",
"cap-color \n",
"Brown 2284 2284 2284 2284 2284 2284 \n",
"Buff 168 168 168 168 168 168 \n",
"Cinnamon 44 44 44 44 44 44 \n",
"Green 1856 1856 1856 1856 1856 1856 \n",
"Pink 144 144 144 144 144 144 \n",
"Purple 16 16 16 16 16 16 \n",
"Red 1500 1500 1500 1500 1500 1500 \n",
"White 1040 1040 1040 1040 1040 1040 \n",
"Yellow 1072 1072 1072 1072 1072 1072 \n",
"\n",
" gill-spacing gill-size gill-color stalk-shape ... \\\n",
"cap-color ... \n",
"Brown 2284 2284 2284 2284 ... \n",
"Buff 168 168 168 168 ... \n",
"Cinnamon 44 44 44 44 ... \n",
"Green 1856 1856 1856 1856 ... \n",
"Pink 144 144 144 144 ... \n",
"Purple 16 16 16 16 ... \n",
"Red 1500 1500 1500 1500 ... \n",
"White 1040 1040 1040 1040 ... \n",
"Yellow 1072 1072 1072 1072 ... \n",
"\n",
" stalk-surface-below-ring stalk-color-above-ring \\\n",
"cap-color \n",
"Brown 2284 2284 \n",
"Buff 168 168 \n",
"Cinnamon 44 44 \n",
"Green 1856 1856 \n",
"Pink 144 144 \n",
"Purple 16 16 \n",
"Red 1500 1500 \n",
"White 1040 1040 \n",
"Yellow 1072 1072 \n",
"\n",
" stalk-color-below-ring veil-type veil-color ring-number \\\n",
"cap-color \n",
"Brown 2284 2284 2284 2284 \n",
"Buff 168 168 168 168 \n",
"Cinnamon 44 44 44 44 \n",
"Green 1856 1856 1856 1856 \n",
"Pink 144 144 144 144 \n",
"Purple 16 16 16 16 \n",
"Red 1500 1500 1500 1500 \n",
"White 1040 1040 1040 1040 \n",
"Yellow 1072 1072 1072 1072 \n",
"\n",
" ring-type spore-print-color population habitat \n",
"cap-color \n",
"Brown 2284 2284 2284 2284 \n",
"Buff 168 168 168 168 \n",
"Cinnamon 44 44 44 44 \n",
"Green 1856 1856 1856 1856 \n",
"Pink 144 144 144 144 \n",
"Purple 16 16 16 16 \n",
"Red 1500 1500 1500 1500 \n",
"White 1040 1040 1040 1040 \n",
"Yellow 1072 1072 1072 1072 \n",
"\n",
"[9 rows x 22 columns]"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>class</th>\n",
" <th>cap-shape</th>\n",
" <th>cap-surface</th>\n",
" <th>bruises</th>\n",
" <th>odor</th>\n",
" <th>gill-attachment</th>\n",
" <th>gill-spacing</th>\n",
" <th>gill-size</th>\n",
" <th>gill-color</th>\n",
" <th>stalk-shape</th>\n",
" <th>...</th>\n",
" <th>stalk-surface-below-ring</th>\n",
" <th>stalk-color-above-ring</th>\n",
" <th>stalk-color-below-ring</th>\n",
" <th>veil-type</th>\n",
" <th>veil-color</th>\n",
" <th>ring-number</th>\n",
" <th>ring-type</th>\n",
" <th>spore-print-color</th>\n",
" <th>population</th>\n",
" <th>habitat</th>\n",
" </tr>\n",
" <tr>\n",
" <th>cap-color</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Brown</th>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>...</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" <td>2284</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Buff</th>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>...</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" <td>168</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Cinnamon</th>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>...</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Green</th>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>...</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" <td>1856</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Pink</th>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>...</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" <td>144</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Purple</th>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>...</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Red</th>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>...</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>White</th>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>...</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" <td>1040</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Yellow</th>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>...</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" <td>1072</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>9 rows × 22 columns</p>\n",
"</div>"
]
},
"metadata": {},
"execution_count": 9
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Donut chart"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 10,
"source": [
"habitat=mushrooms.groupby(['habitat']).count()\n",
"habitat"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" class cap-shape cap-surface cap-color bruises odor \\\n",
"habitat \n",
"Grasses 2148 2148 2148 2148 2148 2148 \n",
"Leaves 832 832 832 832 832 832 \n",
"Meadows 292 292 292 292 292 292 \n",
"Paths 1144 1144 1144 1144 1144 1144 \n",
"Urban 368 368 368 368 368 368 \n",
"Waste 192 192 192 192 192 192 \n",
"Wood 3148 3148 3148 3148 3148 3148 \n",
"\n",
" gill-attachment gill-spacing gill-size gill-color ... \\\n",
"habitat ... \n",
"Grasses 2148 2148 2148 2148 ... \n",
"Leaves 832 832 832 832 ... \n",
"Meadows 292 292 292 292 ... \n",
"Paths 1144 1144 1144 1144 ... \n",
"Urban 368 368 368 368 ... \n",
"Waste 192 192 192 192 ... \n",
"Wood 3148 3148 3148 3148 ... \n",
"\n",
" stalk-surface-above-ring stalk-surface-below-ring \\\n",
"habitat \n",
"Grasses 2148 2148 \n",
"Leaves 832 832 \n",
"Meadows 292 292 \n",
"Paths 1144 1144 \n",
"Urban 368 368 \n",
"Waste 192 192 \n",
"Wood 3148 3148 \n",
"\n",
" stalk-color-above-ring stalk-color-below-ring veil-type \\\n",
"habitat \n",
"Grasses 2148 2148 2148 \n",
"Leaves 832 832 832 \n",
"Meadows 292 292 292 \n",
"Paths 1144 1144 1144 \n",
"Urban 368 368 368 \n",
"Waste 192 192 192 \n",
"Wood 3148 3148 3148 \n",
"\n",
" veil-color ring-number ring-type spore-print-color population \n",
"habitat \n",
"Grasses 2148 2148 2148 2148 2148 \n",
"Leaves 832 832 832 832 832 \n",
"Meadows 292 292 292 292 292 \n",
"Paths 1144 1144 1144 1144 1144 \n",
"Urban 368 368 368 368 368 \n",
"Waste 192 192 192 192 192 \n",
"Wood 3148 3148 3148 3148 3148 \n",
"\n",
"[7 rows x 22 columns]"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>class</th>\n",
" <th>cap-shape</th>\n",
" <th>cap-surface</th>\n",
" <th>cap-color</th>\n",
" <th>bruises</th>\n",
" <th>odor</th>\n",
" <th>gill-attachment</th>\n",
" <th>gill-spacing</th>\n",
" <th>gill-size</th>\n",
" <th>gill-color</th>\n",
" <th>...</th>\n",
" <th>stalk-surface-above-ring</th>\n",
" <th>stalk-surface-below-ring</th>\n",
" <th>stalk-color-above-ring</th>\n",
" <th>stalk-color-below-ring</th>\n",
" <th>veil-type</th>\n",
" <th>veil-color</th>\n",
" <th>ring-number</th>\n",
" <th>ring-type</th>\n",
" <th>spore-print-color</th>\n",
" <th>population</th>\n",
" </tr>\n",
" <tr>\n",
" <th>habitat</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Grasses</th>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>...</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" <td>2148</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Leaves</th>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>...</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" <td>832</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Meadows</th>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>...</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" <td>292</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Paths</th>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>...</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" <td>1144</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Urban</th>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>...</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" <td>368</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Waste</th>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>...</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" <td>192</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Wood</th>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>...</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" <td>3148</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7 rows × 22 columns</p>\n",
"</div>"
]
},
"metadata": {},
"execution_count": 10
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 11,
"source": [
" \n",
"labels=['Grasses','Leaves','Meadows','Paths','Urban','Waste','Wood']\n",
"\n",
"plt.pie(habitat['class'], labels=labels,\n",
" autopct='%1.1f%%', pctdistance=0.85)\n",
" \n",
"center_circle = plt.Circle((0, 0), 0.40, fc='white')\n",
"fig = plt.gcf()\n",
"\n",
"fig.gca().add_artist(center_circle)\n",
" \n",
"# Adding Title of chart\n",
"plt.title('Mushroom Habitats')\n",
" \n",
"plt.show()"
],
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAD3CAYAAADFeRJuAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO2dd3xUZfb/32cmvUJCgIQAoRMgCChFIIBiDwq2Rdfedi1rXV3zdRuursZ1LT8V19XVlRV7V2IvSAcbHemhJYQQIKRnyvn9cW9gCOltSu779ZpXZp773OeeO5nPffo5oqpYWFgEDjZvG2BhYdG6WKK2sAgwLFFbWAQYlqgtLAIMS9QWFgGGJWoLiwDDErUXEZGXReRBb9vRHojI1SKyqJ7jn4rIVe1pU6BiiboeRCRHRKpEpEuN9J9FREUkxTuWtT/md3FajbR6hdoUVPVsVZ3TnHJFJMX8fwS1hi3+jiXqhtkOXFr9QUTSgIj2NsL6wVo0FkvUDfMKcKXH56uA/3lmEJH5InK9x+c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HlxQybCuNmYMDm7Q1K5yMFD/1wOAb1Iysx8AHmjBQNpQ4Kd6jo8ChqvqAbO2Pl9VD4tIF2CZiHyEsaw3V1UzAEQkVkTigfOBweYuvk5mef8PeMLTSQfG5qK7gVtUdbGIRAEVNBGrpm4Os2IjmBU7B3idGoIGuHpEMJ9dHnFMWtaiSqb2CWLzrVFM7RNE1qLjp18jguF/M8JYd3MUn10ewR2fV3CoQlmd7yI8SFh9UxTf57ooqlDyit0s3+NqlKAB4qQ4ouFcfosdmAV8lZKZndgaBYrIbLPG/d5M+tJ
},
"metadata": {}
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Waffle chart"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 12,
"source": [
"pip install pywaffle"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: pywaffle in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.6.3)\n",
"Requirement already satisfied: matplotlib in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pywaffle) (3.1.0)\n",
"Requirement already satisfied: python-dateutil>=2.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from matplotlib->pywaffle) (2.8.0)\n",
"Requirement already satisfied: numpy>=1.11 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from matplotlib->pywaffle) (1.19.2)\n",
"Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from matplotlib->pywaffle) (2.4.0)\n",
"Requirement already satisfied: cycler>=0.10 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from matplotlib->pywaffle) (0.10.0)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from matplotlib->pywaffle) (1.1.0)\n",
"Requirement already satisfied: six>=1.5 in /Users/jenlooper/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.1->matplotlib->pywaffle) (1.12.0)\n",
"Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->pywaffle) (45.1.0)\n",
"\u001b[33mWARNING: You are using pip version 20.2.3; however, version 21.2.3 is available.\n",
"You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -m pip install --upgrade pip' command.\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 13,
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from pywaffle import Waffle\n",
" \n",
"# creation of a dataframe\n",
"\n",
"\n",
"data ={'color': ['brown', 'buff', 'cinnamon', 'green', 'pink', 'purple', 'red', 'white', 'yellow'],\n",
" 'amount': capcolor['class']\n",
" }\n",
" \n",
"df = pd.DataFrame(data)\n",
" \n",
"# To plot the waffle Chart\n",
"fig = plt.figure(\n",
" FigureClass = Waffle,\n",
" rows = 100,\n",
" values = df.amount,\n",
" labels = list(df.color),\n",
" figsize = (30,30),\n",
" colors=[\"brown\", \"tan\", \"maroon\", \"green\", \"pink\", \"purple\", \"red\", \"whitesmoke\", \"yellow\"],\n",
")\n",
"\n",
"\n"
],
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Waffle size 2160x2160 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAABucAAAhoCAYAAADRSGMJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nOzdfZiWdZ03/s8Fw9NIakJhGjKWhogwIGSaIJql7QFrZXhvoZm6lWlbrrrVvdXtyNY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t8xdqz5/NldX50rX8nat+vzZ3DJ3rfr82Vxdnauqda36/NlcXZ0rXUva9eK9j49nVq+d8koytrXbqL3ib1bdHBEtPVsfbemJ6HnRndQVV1wfra1D49RTZ+4kfdvMnefuumxuvmr1er3I6wEAAAAAANBHurq6VrS3t6/Z8vvcWi3ZYm6Ljnp9UerMMuvq6hrZ3t7etquv97WWAAAAAAAAFOYf//EfR7zpTW86eOzYsQe/+93v3v+8887b54ILLhgVEXHYYYeNPeuss/adMGHCuLa2tkN+9KMfDY+IuPTSS0ccd9xxb5w+ffqBY8aMOeSjH/3o67fknXzyyfsdcsgh4w444IDx55577j5bHt93330nfOxjH9v3oIMOOviQQw4Zt3DhwtZp06YdOHr06EO+/OUvvyYiore3N84888zXH3jggePf9KY3HXzllVe+OiLixhtvfNVhhx029p3vfOcb9t9///EnnHDC/r29vUnm3+FH/eaNH78qEn3Mcs6yZXs
},
"metadata": {
"needs_background": "light"
}
}
],
"metadata": {}
}
],
"metadata": {
"orig_nbformat": 4,
"language_info": {
"name": "python",
"version": "3.7.0",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.0 64-bit"
},
"interpreter": {
"hash": "70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d"
}
},
"nbformat": 4,
"nbformat_minor": 2
}