0

On the column for status

enter image description here

I want set status as 1 if diff is less than 0 and 1 if is more than 1.

Jonas
  • 725
  • 5
  • 23
Kgabo
  • 1

2 Answers2

1

You can use np.where to choose 1 or '' depending on the condition.

Use this:

import numpy as np

df_small["status"] = np.where((df_small["diff"] < 0) | (df_small["diff"] > 1), 1, '')
Shubham Sharma
  • 68,127
  • 6
  • 24
  • 53
1

You can use np.where or, if you prefer, you can simply apply a lambda function like this:

df['status'] = df['diff'].apply(lambda val: 1 if val < 0 or val > 1 else np.nan)

As default value you can use np.nan or any other value that you like.

Marco Caldera
  • 485
  • 2
  • 7
  • 16