0

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

1 Answers1

1

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')
  • how can I add mathematical calulations to it? for eg if instead of 1 I had 1.1, then you cannot use time-B>time-c. – MemeFast King Nov 21 '22 at 04:37
  • 1
    If we need to add calculation, we'll use mask like this one https://stackoverflow.com/questions/15315452/selecting-with-complex-criteria-from-pandas-dataframe or you can update the question I'll take a look on it. – Nguyễn Vũ Trung Hiếu Nov 21 '22 at 09:07