Jupyter notebook exercise

I am trying to calculate the percentage of dissatisfied employees in each

service_cat group by using the DataFrame.pivot_table() method.

Guided Project_ Clean and Analyze Employee Exit Surveys (2).tar (1.6 MB)

Click here to view the jupyter notebook file in a new tab

Thank you
-Salem

I get the idea of the DataFrame.pivot_table() method. However, I feel like with categorical variables, you would have to use the DataFrame.pivot() method instead.
-Salem

1 Like

Thanks for the help! Also, when I run the last code block, I get this error:


I’m not sure what exactly what I am doing wrong. I did restart the kernel and ran everything a couple of times, but it did not work.
-Salem

1 Like

Hi @salemabdulkerim,

Are you running the same notebook as the one you initially posted? It looks like you have 104 code cells now compared to the initial 103.

My hunch is combined_updated was modified before cell [104]. You can try not assigning any modification to combined_updated and use a different variable.

Or if that doesn’t fix things, you can share your .ipynb (.tar is also fine) here and I can have a look.

2 Likes

Hello there. Thank you for the response. Yeah I am running the same notebook. I’ll take a look at combined_updated thought.
Thanks again!
-Salem

Attached is my .ipynb
Guided Project_ Clean and Analyze Employee Exit Surveys (3).tar (1.6 MB)
Thank you
-Salem

1 Like

Hi @salemabdulkerim,

I tried running your notebook and it seems to be working fine. I’m just making sure I got the right notebook.

Basics.ipynb (539.1 KB)

Click here to view the jupyter notebook file in a new tab


Oops…it doesn’t work now when I uploaded it here. Interestingly it worked on my computer; quite odd.

1 Like

After reading this:

One possible solution is this:

combined_updated["dissatisfied"] = combined_updated["dissatisfied"].apply(pd.to_numeric)
combined_updated = pd.pivot_table(combined_updated, values = 'dissatisfied', index = ['service_cat'])
combined_updated

Basics.ipynb (533.5 KB)

Click here to view the jupyter notebook file in a new tab

2 Likes

Thanks for the response. I did that and I am still getting errors
-Salem

1 Like

Hmm…after reviewing your code, it is possible that the problem is way up around code cell [56]:

tafe_resignations[['Contributing Factors. Dissatisfaction', 'Contributing Factors. Job Dissatisfaction']].applymap(update_vals)
# Applies some of the column names from the tafe_resignations dataframe and sees if any of them contain a true, false , or NaN value. If it is false, then it will not be in a column called 
# dissatisfied

You did not reassign back the transformed data frame to tafe_resignations. I don’t clearly understand what you’re trying to achieve but my best guess is it should be like this:

tafe_resignations[['Contributing Factors. Dissatisfaction', 'Contributing Factors. Job Dissatisfaction']] = tafe_resignations[['Contributing Factors. Dissatisfaction', 'Contributing Factors. Job Dissatisfaction']].applymap(update_vals)
# Applies some of the column names from the tafe_resignations dataframe and sees if any of them contain a true, false , or NaN value. If it is false, then it will not be in a column called 
# dissatisfied
2 Likes

It worked. Thanks for the help!
-Salem

1 Like

No worries @salemabdulkerim.