1

I have the below data frame:

Account Current_Value   Limit   Acc_number
acc1    23              50      8975345
acc2    45              100     7643783
acc3    32              80      7872643
acc4    344             400     9784323
acc5    222             300     3235334
acc6    677             700     6453543

I want to iterate through each of the rows and get the percentage of Current_value over the Limit and if it's above n ( say 95%) I would like to create a new Column Limit_exceeded to Yes/No.

Sample output:

Account Current_Value   Limit   Acc_number  Limit_exceeded
acc1    23              50      8975345     No
acc2    45              100     7643783     No
acc3    78              80      7872643     Yes
acc4    344             400     9784323     No
acc5    222             300     3235334     No
acc6    690             700     6453543     Yes
1
  • df['Limit_exceeded'] = df['Current_Value'].gt(df['Limit']*0.95) ? Commented Aug 30, 2022 at 2:53

1 Answer 1

2

One may use numpy.where. Hence

import numpy as np

df['Limit_exceeded'] = np.where(df['Current_Value'] / df['Limit'] > 0.95, 'Yes', 'No')

Alternatively, one may use pandas.Series.map:

df['Limit_exceeded'] = (df['Current_Value'] / df['Limit'] > 0.95).map({True: 'Yes', False: 'No'})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.