Problems with a pandas aggregate function exercise

While I was doing the project for the pandas aggregate function class at Codecademy (, I wasn’t able to get through an exercise, more specifically exercise number 6. The exercise asked the student to do the following:

6.Create a new column in clicks_pivot called percent_clicked which is equal to the percent of users who clicked on the ad from each utm_source .

Was there a difference in click rates for each source?

The table he is referring to is this:

False represents the users who didn’t click on it and True represents the user who clicked.

The code I used was this:

clicks_pivot['percent_clicked'] = 
clicks_pivot[True] / (clicks_pivot[True] + clicks_pivot[False])

I tried everything but I always got the same error message: KeyError: True

Can anyone help me?


You are trying to call on columns named True and False, but you don’t have any.

Try going back to the previous step where you create the clicks_pivot table. If you read it carefully, you’ll see where the issue lies.

1 Like

But when we use those brackets aren’t we referring to the index of the row? If we were simply referring to a column we would use clicks_pivot.True not brackets, so it should work anyway because True and False are the indexes.

No, both brackets and the dot method reference columns:

1 Like

Oh I dind’t know that, thank you! I will try doing the exercise again but now creating the columns to see if it works.

1 Like