Question about the initial analysis

Hi all, I have below questions. Please help!!

1,We tried to calculate the percentage of the employee who resigned due to dissatisfaction. In the dissatisfied columns, we only have True and False. True means that employee resigned due to dissatisfaction. When python calculated the percentage by df.pivot_table, how does it know calculate only True value? I also use df.groupby,agg() to get the same output as I used df.pilvot_table().I just tried agg(mean), it works. but i dont know why i can use mean to calculate the columns which datatype is string.

2, How to move the legend to the upper center?

Thank you so much in advance !!

Screen Link: https://app.dataquest.io/m/348/guided-project%3A-clean-and-analyze-employee-exit-surveys/10/perform-initial-analysis

My Code:

resignation_per=combined_updated.pivot_table(index='service_cat',values='dissatisfied')
print(resignation_per)

combined_updated.groupby('service_cat')['dissatisfied'].agg(np.mean)



# Plot the results
%matplotlib inline
resignation_per.plot(kind='bar',legend=True, rot=30)

What I expected to happen:
I expected the output with 2 percentage number, one is calculated for True, another one is calculated for False.

What actually happened:

             dissatisfied
service_cat              
Established      0.774194
Experienced      0.581395
New              0.476684
Veteran          0.808824

Hi @candiceliu93

  1. Python makes the calculation same way as us. I mean it counts how many trues and falses are and divide them by the total amount of rows.

  2. To change the location of the legend box you can use plt.legend(loc=9), or you can use loc=‘0’ to find the best location. The documentation can help you with that