AGGREGATES IN PANDAS A/B Testing for ShoeFly.com

Hello,
task 3 of this project, i want to try another way to make the task :
" 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."

I tried this code :
ad_clicks['is_click']= ad_clicks['ad_click_timestamp'].apply(lambda ad_click_timestamp: 'True' if ad_click_timestamp == 'NaN' else 'False' )

ad_clicks['is_click']= ad_clicks['ad_click_timestamp'].apply(lambda x: 
                                                             'True' if
                                                             x  == 'NaN'
                                                             else 'False'
                                                            )

Somethings wrong because all is False or True. Should someone can help me to understand what’s wrong, please. Thanks
AGGREGATES IN PANDAS A/B Testing for ShoeFly.com

2 Likes

I have a similar question. I also tried to go about task #3 in a different way since we have not been taught the example used in the hint. I do not understand why my code is also producing all “True”.

ad_clicks['is_click'] = ad_clicks.apply(lambda row: True if row.ad_click_timestamp != 'nan' else False, axis = 1)

I then tried replacing ‘nan’ with ‘null’ and it still shows every row as True. My code follows the exact same format used in the Petal Power inventory project so I am also at a loss as to why it is not working for this one.

1 Like

It doesn’t take ‘NaN’ etc… as null or whatever you want to call it. [at least it seems that way for me]. There is however a .isnull() and `~’ and you can use with null/NaN values.