A/B Testing for ShoeFly.com project

Hi everyone. I’m confused about an exercise. I need to calculate the percentage of people who clicked an ad, that info is stored as True if there clicked the ad, and false if they did not.
There is the data frame
Now I want to calculate the percentage in a new column. I’m doing this
'cause True and False are the names of the data frame columns. But I’m getting an error. Looking for the hint the correct way is this one
But I don’t understand why they use True and False like variables if they are the column’s name.
Can you explain me why am I wrong? Thanks

In pandas dataframes, column names are considered strings and should be accessed as such. When you write clicks pivot['True'], pandas will look for a column named “True” in the dataframe, which does not exist in your case.

Instead, you should use the string representations of the column names when referencing them, like this: clicks_pivot['true'] and clicks_pivot['false'].

So the correct code for calculating the percentage of people who clicked an ad would be:

clicks_pivot['percent clicked'] = clicks_pivot['true'] / (clicks_pivot['true'] + clicks_pivot['false']) * 100

Here we divide the number of people who clicked by the total number of clicks, which is the sum of the “true” and “false” columns. Multiplying by 100 gives us the percentage value.

Hope this helps! :slight_smile: