Rati Goyal
Rati Goyal

Reputation: 69

To get status that dependent on two columns

p_da q_ R
a 5
b 5
b 4
a 3
a 8
b 7
b 6
c 4
b 4

Output should be:

p_da q_ R
a 5 old
b 5 old
b 4 old
a 3 old
a 8 New
b 7 New
b 6 old
c 4 New
b 4 old

R is depends on P_da and q_, first we check p:

How do I get R?

Upvotes: 0

Views: 31

Answers (1)

BENY
BENY

Reputation: 323356

In your case do groupby with transform, then np.where

s = df.groupby('p_da')['q_'].transform('max')
df['R'] = np.where(df['q_'].eq(s), 'New', 'Old')

Upvotes: 1

Related Questions