Home > Net >  Struggling to insert a pie chart in Python
Struggling to insert a pie chart in Python

Time:11-10

I have made a pie chart using an excel sheet but it is coming out incomplete. I am not sure of the reason. Here is the code:

import matlotplib.pyplot as plt
import pandas as pd
import numpy as np
Employee=pd.read_excel("C:\\Users\\Jon\\Desktop\\data science\\Employee.xlsx")
Employee

colors = ["#1f77b4", "#ff7f0e"]
group_by_departments=Employee.groupby("Department").count().reset_index()
sizes = group_by_departments['Gender']
labels = group_by_departments['Department']
plt.pie(sizes, labels=labels, colors = colors,autopct='%.2f %%')
plt.show()

enter image description here

enter image description here

CodePudding user response:

You can use two-leveled pie chart

PS: You could assign a color per gender via:

colors = ["magenta" if gender=="Male" else "deepskyblue" for gender in group_by_departments_and_gender["Gender"]]

This especially helps in case one of the genders wouldn't be present in one of the departments.

  • Related