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!