Guided Project: Clean And Analyze Employee Exit Surveys - Plotting table

Hi,
I have a question in Step 10.

I have created a pivot_table and trying to plot. I am seeing this issue. Can you please help me out?
TypeError: Empty ‘DataFrame’: no numeric data to plot

pv_combined = pd.pivot_table(combined_updated, values=[‘dissatisfied’], index=“service_cat”
,margins=True)
pv_combined.shape
(5,1)

image
pv_combined.shape

Let me know.
Thanks,
Nutan

Hi @universalastrostuden,

I would like to take a look at your Guided Project, please click the Download button at the top of the Jupyter Notebook interface in our platform.

jupyter_guided_project_download.png

This will download a .tar file that contains both your notebook file and the required datasets. Please attach this .tar file with your reply.

Best,
Sahil

Guided Project_ Clean And Analyze Employee Exit Surveys.tar (804.5 KB)

1 Like

Hi @universalastrostuden,

When I ran your notebook file, I received this error:

tafe_resignations["dissatisfied"].value_counts()

KeyError: 'dissatisfied'

This can be fixed by changing this line

tafe_factors = tafe_resignations[factors].applymap(update_vals)

to

tafe_resignations['dissatisfied'] = tafe_resignations[['Contributing Factors. Dissatisfaction', 'Contributing Factors. Job Dissatisfaction']].applymap(update_vals).any(1, skipna=False)

Also

if val == 'NaN':
    return np.nan

in update_vals() should be changed to

if pd.isnull(val):
    return nan

Now the values will be correct, but NaN value counts won’t be displayed unless you add dropna=False argument:

tafe_resignations["dissatisfied"].value_counts(dropna=False)

When I continued execution, I received another error:

pv_combined = pd.pivot_table(combined_updated, values=['dissatisfied'], index="service_cat", margins=True)

KeyError: 'service_cat'

To fix it, you have to change this line

service_cat = years_of_service.apply(whichcat)

into

combined_updated['service_cat'] = years_of_service.apply(whichcat)

The next error is the one you mentioned in your post

pv_combined.plot(kind="bar",xlim=(0,10),title="Dissatisfaction by Service Category",legend=False)

TypeError: Empty 'DataFrame': no numeric data to plot

Here the error is very clear that the DataFrame doesn’t have any numeric data to plot:

             dissatisfied
service_cat              
Established          True
Experienced          True
New                  True
Veteran              True
All                  True

All of the values are True. I would recommend you to go through the solution page and compare it with the code you have used. This will help you identify why you are getting the above values.

Best,
Sahil