A/B Testing for ShoeFly.com

Hello everyone!

I am working on the A/B Testing for ShoeFly.com project and there is a point asking for creating a new column based on the values of another column:

" If the column ad_click_timestamp is not null, then someone actually clicked on the ad that was displayed.

Create a new column called is_click, which is True if ad_click_timestamp is not null and False otherwise.

My first solution was to use a lambda function:

ad_clicks[‘is_click’] = ad_clicks.ad_click_timestamp.apply(lambda x: True if x != “nan” else False)

After running the program I observed the new column values were not correctly set. All of them were set to True.

The suggested solution is:

ad_clicks[‘is_click’] = ~ad_clicks
.ad_click_timestamp.isnull()

Could somebody explain where the difference in the result comes from?

Thank you!

Ah, but NAN is not the same thing as NULL.

NAN means “not a number”, or, the object is not a number, whereas NULL means that the object is empty and not using any memory or pointing to any memory.

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

the tilde, ~ negates the boolean. Or, if the timestamp is not null, then True.

2 Likes

Thanks for your explanation! Now it’s clear and makes sense

2 Likes