MemeFast King
MemeFast King

Reputation: 127

Adding flag according to a condition in Dataframes

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

Upvotes: 0

Views: 969

Answers (1)

Hieu
Hieu

Reputation: 79

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

Upvotes: 1

Related Questions