Reputation: 1
On the column for status
I want set status
as 1
if diff is less than 0
and 1
if is more than 1
.
Upvotes: 0
Views: 496
Reputation: 505
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.
Upvotes: 1
Reputation: 71687
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, '')
Upvotes: 1