Error when creating pivot table with boolean values

Screen Link:

My Code:

new_dissatisfied = combined_updated.pivot_table(values = "service_cat", index = "dissatisfied")
new_dissatisfied.plot(kind = "bar", title = "distribution of dissatisfied employees")

What I expected to happen:

Create a pivot table that aggregates “dissatisifed”
What actually happened:

DataError: No numeric types to aggregate
seems like its not converting my True/False values to 0 and 1

the exercise said " Recall that the dissatisfied column consists of Boolean values, meaning they’re either True or False . Methods such as the df.pivot_table() method actually treat Boolean values as integers, so a True value is considered to be 1 and a False value is considered to be 0 ."

hey @rayolufadeju

you have interchanged the index and values columns while creating the pivot table.

index = dissatisfied!

Did you ever solve this issue? I noticed you used comb_updated.pivot_table() and the instructions say to do it that way. However, all of the documentation says it should go - pd.pivot_table(comb_updated,index=,values=)

I am lost as well.

Hi, yes I solved it. I had switched the index and value columns.

So the documentation says df. pivot_table (self, index, values),
but when you check the parameters, it starts from index and values.
not sure what the technical explanation is but we generally dont add the self (e.g series or df) as a parameter.

Check it out here.

i hope this helps.

did you replace the missing values with ‘False’ or ‘True’ for the ‘dissatisfied’ column? if that column contains missing value, the pivot table won’t work.

I ended up dropping the NaN values in dissatisfied to make sure there were no non-boolean values there. I have correct index and values. I have tried running both pd.pivot_table and combined_updated.pivot_table. I am still getting this same error.

Replying to my own post, the problem was that my dissatisfied column was the wrong datatype - object. I needed to change the datatype of that column to bool before doing the pivot_table.


Thanks @joarvat, you just saved me after an hour of pure frustration!! I had the same problem…