πŸ„ Mushroom ProportionsΒΆ

Import the mushroom dataset

import pandas as pd
import matplotlib.pyplot as plt
mushrooms = pd.read_csv('../../../data/mushrooms.csv')
mushrooms.head()

Pie chartΒΆ

Create a pie chart displaying the proportion of Poisonous vs. Edible mushrooms

print(mushrooms.select_dtypes(["object"]).columns)
cols = mushrooms.select_dtypes(["object"]).columns
mushrooms[cols] = mushrooms[cols].astype('category')
edibleclass=mushrooms.groupby(['class']).count()
edibleclass
labels=['Edible','Poisonous']
plt.pie(edibleclass['population'],labels=labels,autopct='%.1f %%')
plt.title('Edible?')
plt.show()
capcolor=mushrooms.groupby(['cap-color']).count()
capcolor

Donut chartΒΆ

habitat=mushrooms.groupby(['habitat']).count()
habitat
  
labels=['Grasses','Leaves','Meadows','Paths','Urban','Waste','Wood']

plt.pie(habitat['class'], labels=labels,
        autopct='%1.1f%%', pctdistance=0.85)
  
center_circle = plt.Circle((0, 0), 0.40, fc='white')
fig = plt.gcf()

fig.gca().add_artist(center_circle)
  
# Adding Title of chart
plt.title('Mushroom Habitats')
  
plt.show()

Waffle chartΒΆ

pip install pywaffle
import pandas as pd
import matplotlib.pyplot as plt
from pywaffle import Waffle
  
# creation of a dataframe


data ={'color': ['brown', 'buff', 'cinnamon', 'green', 'pink', 'purple', 'red', 'white', 'yellow'],
    'amount': capcolor['class']
     }
  
df = pd.DataFrame(data)
  
# To plot the waffle Chart
fig = plt.figure(
    FigureClass = Waffle,
    rows = 100,
    values = df.amount,
    labels = list(df.color),
    figsize = (30,30),
    colors=["brown", "tan", "maroon", "green", "pink", "purple", "red", "whitesmoke", "yellow"],
)