Check each value in a dataframe and if that is less means then change the value which is given

Viewed 19
cateory Percentage
    AB      99
    CD      65
    EF      12
    GH      25
    IJ      90
    KL      100

If CD's percentage is less than 70 then change that as 71 else existing value is fine If EF's percentage is less than 20 then change that as 21 else existing value is fine If GH's percentage is less than 30 then change that as 45 else existing value is fine For AB existing value is fine

Output

cateory Percentage
    AB      99
    CD      65
    EF      21
    GH      45
    IJ      90
    KL      100
1 Answers

Create list of tuples for replacement by compare both columns and if match replace by new value - last value of tuple:

L = [('CD', 70, 71), ('EF', 20, 21), ('GH', 30, 45)]

for cat, less, new in L:
    m = df['cateory'].eq(cat) & df['Percentage'].lt(less)
    df.loc[m, 'Percentage'] = new
print (df)
  cateory  Percentage
0      AB          99
1      CD          71
2      EF          21
3      GH          45
4      IJ          90
5      KL         100
Related