Help with a/b test project

I am working on the A/B testing for

The task says " 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."

The hint says " ad_clicks['is_click'] = ~ad_clicks.ad_click_timestamp.isnull()" this makes sense although in the lessons I thought you had to create a lamba function in order to do this.

So, my original approach was
ad_clicks['is_click'] = ad_clicks.ad_click_timestamp.apply(lambda x: False if x.isnull() else True)

But I get an error saying 'str' object has no attribute 'isnull'. Can someone explain why the hint code, which applies “isnull()” to ad_click_timestamp works but using it the way i did it doesn’t?

1 Like

I had exactly the same question!

Hi @code5344275110 welcome to the forums.

The hint refers to the inverse operator, the tilde, or, “~” .
The ~ operator checks for the inverse on the function .isnull() . You don’t need a lambda function.

More on that:

Also, you’re applying the .isnull() function to the timestamp series.

Check out the documentation for the .isnull() function:

The .apply() function is applied to a Pandas series.

My understanding is that your error, “string object has no attribute, ‘isnull’” means that the string, when using the .apply() function on timestamp, timestamp has no attribute “isnull”.

Python is an object-oriented programming language. To read up on objects and attributes try here:

I need more coffee. :coffee: :slight_smile:

you’re applying a function on a function–.isnull() on .apply().

To my knowledge, you cannot do that…

I understand why the .isnull() method works but I tried the below approach first but it didn’t work. My question is why?

ad_clicks[‘is_click’] = ad_clicks[‘ad_click_timestamp’] != None