0

can you please tell me about this question: I have a dataframe

enter image description here

I want to do the following with it: if the line in the proba column is nan, then change the value in the corresponding line in the flag column to 0. How can I do this?

Sam324
  • 147
  • 1
  • 11

1 Answers1

0

Try with isna and loc:

df.loc[df['proba'].isna(), 'flag'] = 0

Or np.where:

df['flag'] = np.where(df['proba'].isna(), 0, df['flag'])
U12-Forward
  • 65,118
  • 12
  • 70
  • 89