How to get absolute difference of 2 variable.
AnsweredHi Team,
Hope you are doing great.
i am havig a this df.
week | Actual (A) | Forecast (F) |
1 | 122 | NaN |
2 | 105 | NaN |
3 | 93 | NaN |
4 | 113 | NaN |
5 | 107 | NaN |
6 | 115 | 122*<gurobi.Var *Awaiting Model Update*> + 105*<gurobi.Var *Awaiting Model Update*> + 93*<gurobi.Var *Awaiting Model Update*> +113*<gurobi.Var *Awaiting Model Update*> + 107*<gurobi.Var *Awaiting Model Update*> |
7 | 111 | 105*<gurobi.Var *Awaiting Model Update*> + 93*<gurobi.Var *Awaiting Model Update*> +113*<gurobi.Var *Awaiting Model Update*> + 107*<gurobi.Var *Awaiting Model Update*> + 115 * <gurobi.Var *Awaiting Model Update*> |
I want to get the Absolute differrence of | A - F |
Please describe this term
Thanks
Munasib
-
Hi Team,
Hope you are doing good.
i am looking forward to your reply.
Thanks
Munasib
0 -
Hi Munasib,
Noting that the API docs for abs_ indicate that the argument must be a variable, and not an expression, we know that we will need to create an auxiliary variable for each row, that will be equal to A-F. You can add these variables to the dataframe, although you do not have to - you could create them on "the fly".
In Advanced Patterns in the gurobipy-pandas docs we describe how to add SOS constraints, as there is no built-in method for this in gurobipy-pandas. Likewise there is no built in method for abs_ so the approach will be very similar. You will create a column of variables which will be equal to the desired result, and then iterate through the dataframe, row by row, using itertuples, and create the constraint inside the for loop (and possibly the auxiliary variable if you are creating it as you go and do not want to store it anywhere).
- Riley
0
Please sign in to leave a comment.
Comments
2 comments