1

I have 2 columns in a dataframe and I am trying to enter into a condition based on if the second one is NaN and First one has some values, unsuccessfully using:

if np.isfinite(train_bk['Product_Category_1']) and np.isnan(train_bk['Product_Category_2'])

and

   if not (train_bk['Product_Category_2']).isnull() and (train_bk['Product_Category_3']).isnull()
frogatto
  • 28,539
  • 11
  • 83
  • 129
muni
  • 1,263
  • 4
  • 22
  • 31

1 Answers1

0

I would use eval:

df.eval(' ind =  ((pc1==pc1) & (pc2!=pc2) )*2+((pc1==pc1)&(pc2==pc2))*3')
df.replace({'ind':{0:1})