A/B Testing for ShoeFly.com (Task 6)

I was working on this Pandas project and had a question on task 6.

First I tried.

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

However I get an error when I use the quotations with the brackets. Following that I used the hint answer below.

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

Why does True and False work as keys but strings of true and false don’t?

Best.

Do you have a link to the project? I’d assume it’s the fact that True != 'True' and the same for False, so if your columns are the boolean values True and False then you would need to use those are the keys to access them as they are not the same as the strings.

See for example the behaviour for dictionaries.

test = { True: 'heave', 'True': 'ho' } # they are unique keys in a dictionary print(test) print(True == 'True')

The task is under https://www.codecademy.com/learn/data-processing-pandas → aggregates in panda → Project A/B Testing for ShoeFlycom → Task 6.

Here is the code above the portion I cited previously.

 how many clicks from each source
ad_clicks['is_click'] = ~ad_clicks.ad_click_timestamp.isnull()

print(ad_clicks.head())

# how many clicks by soure and actual clicks
clicks_by_source = ad_clicks.groupby(['utm_source', 'is_click']).user_id.count().reset_index()

print(clicks_by_source.head())

# pivot to make source the index column
clicks_pivot = clicks_by_source.pivot(index='utm_source', columns='is_click', values='user_id').reset_index()

I see what your saying, its a different type. So in this code when it does

ad_clicks['is_click'] = ~ad_clicks.ad_click_timestamp.isnull()

it is setting the type of the result to boolean, then when the below is run.

# pivot to make source the index column
clicks_pivot = clicks_by_source.pivot(index='utm_source', columns='is_click', values='user_id').reset_index()

It sets the columns of the pivot to the boolean True instead of ‘True’

Does that logic flow for you?

1 Like

I’m not entirely sure what ad_clicks is here so I think the real question is does the logic flow for you? If you’re not sure do some digging around and get some prints in there or something to find out.

I think you’re in the right area though, the .isnull pandas.isnull — pandas 1.3.3 documentation method will return an array of booleans and that’s what you’re working with. I think it’s worth having a little look at the output so you know what’s there, after all, why guess the contents when you can know for sure :slightly_smiling_face:.