1

I have the following dataframe:

Policy_id Value 
     A           xyz
     B           abc
     A           pqr
     C           lmn

And I want to use np.where() such that whenever the policy_id is equal to A the corresponding value must be appended with a *.

Policy_id    Value 
     A           xyz*
     B           abc
     A           pqr*
     C           lmn

How do I achieve this?

tdy
  • 36,675
  • 19
  • 86
  • 83

2 Answers2

0

Try

df['new'] = np.where(df['Policy_id'].eq('A'),df['Value']+'*',df['Value'])
BENY
  • 317,841
  • 20
  • 164
  • 234
0

If you want to modify your dataframe in place and use np.where:

df['Value'] += np.where(df['Policy_id'].eq('A'), '*', '')

output:

  Policy_id Value
0         A  xyz*
1         B   abc
2         A  pqr*
3         C   lmn
mozway
  • 194,879
  • 13
  • 39
  • 75