-1

I have a column with dates called "Click Date". Basically, I'm trying to write an IF statement to return IF there is a date or not in the column. IF click date contains any information, then "1" else "0".

Click Date Column example in Python/Pandas

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

2 Answers2

1

Take a look at the notna() method from pandas here.

In your case it should look something like this, where the boolean values are saved in a new column called valid_dates.

import pandas as pd
df['valid_dates'] = pd.notna(df['click_dates'])
HSM
  • 21
  • 3
0

If you are using numpy, you can return 0 or 1 depending if there's a date in a specific column with the following code:

import numpy as np
df["new_col"]=np.where(df["click_date"].isnull(), 0, 1)
Broken_Window
  • 2,037
  • 3
  • 21
  • 47
TaxpayersMoney
  • 669
  • 1
  • 8
  • 26