Problem #8 in this project reads as follows: Using the column is_click that we defined earlier, check to see if a greater percentage of users clicked on Ad A or Ad B.
Ok, so the “percentage of users” that is shown in the walkthrough video results in:
print(ad_clicks
.groupby([‘experimental_group’, ‘is_click’]).user_id
.count()
.reset_index()
.pivot(
index = ‘experimental_group’,
columns = ‘is_click’,
values = ‘user_id’
)
.reset_index()
)
Dataframe Output:
experimental_group False True
0 A 517 310
1 B 572 255
Where in this result do you see a percentage?
I did not see one
So I went about further writing a script that could calculate the percentage but it still only shows up as a decimal point rather than a percentage. Here is what I wrote:
ad_clicks_pivot = ad_clicks
.groupby([‘experimental_group’, ‘is_click’]).user_id
.count()
.reset_index()
.pivot(
index = ‘experimental_group’,
columns = ‘is_click’,
values = ‘user_id’
)
.reset_index()
ad_clicks_pivot[‘percent_clicked’]= ad_clicks_pivot[True]
/(ad_clicks_pivot[True] + ad_clicks_pivot[False])
print(ad_clicks_pivot)
Output:
experimental_group False True percent_clicked
0 A 517 310 0.374849
1 B 572 255 0.308343
How do I go about making the ‘percent_clicked’ column into an actual percentage rather than a decimal point? i.e.: 37.48% & 30.83% respectively.
TYIA