I am learning how to use aggregates in pandas. In a project, I am asked to create a new column in a dataframe based on values from another column. The instruction reads like this:
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
I have been under the impression, that I can solve this by using a lambda function:
ad_clicks['is_click'] = ad_clicks['ad_click_timestamp'].apply(lambda x: x.notnull())
However, this evaluates to an error:
AttributeError: 'str' object has no attribute 'notnull'
I then tried:
ad_clicks['is_click'] = ad_clicks['ad_click_timestamp'].apply(lambda x: True if x != 'nan' else False)
However, in this case all values of my newly created column evaluate to
How can I use a lambda function to solve this exercise ?