Home > database >  Adding flag according to a condition in Dataframes
Adding flag according to a condition in Dataframes

Time:11-21

Suppose I have a dataframe that looks likes this->

ID time-A time-B time-C
A  30     40     50
B  NULL   60     50
C  30     20     50

I want to add a flag such that if time-A is NULL and time-B/time-c>=1 I put 'Y' flag otherwise I put 'N'
Desired result->

ID time-A time-B time-C Flag
A  30     40     50     N
B  NULL   60     50     Y
C  30     20     50     N

CodePudding user response:

Could try this one :D

import numpy as np
df['Flag'] = np.where((df['time-A'].isna() & (df['time-B']>df['time-C'])), 'Y', 'N')
  • Related