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
  • 27,475
  • 10
  • 76
  • 119
muni
  • 1,165
  • 4
  • 18
  • 29

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})