data = {ID': ['D','R','R','R','R'],
'Calc_Var': [4,3,12,19,8],
'Var': [5,5,10,20,20],
'Adjusted':[5,5,20,20,10]
}
df = pd.DataFrame (data)
print(df)
Looking for an efficient solution to filter on ID (where value = 'R') and then to evaluate 'Calc_var' against 'Var'. 'Var' is essentially master data and has only three values (5, 10, 20). I'm trying to evaluate each row (Calc_var) vs. it's corresponding row (Var) where the logic could be no change, or either an incremental/declining step. The Adjusted_Var would reflect the changes. I drafted a simple DF to illustrate this problem/ outcome. For-loops and iteration are not my best, so I appreciate any help on this one!