'Use variable in excel IF ELSE formula

I have something like this in pandas dataframe:

flag_N = 0
if((df1["DMD"] == 0) & (flag_N == 0)):
     df1["AVL"] = 0
else:
     df1["AVL"] = N_Sup - df1["DMD"]
     flag_N = 1
N_Sup = N_Sup - df1["DMD"]

Above script is in loop, so flag_N and N_Sup values are getting changed on each iteration. Now I want to embed this logic as formula in excel using macro. However, I am not finding any way to assign variables inside if or else statement. Any help will be appreciated. Thanks in advance.



Solution 1:[1]

I believe you simply missed a double quote:

else:
     df1["AVL] = N_Sup - df1["DMD"]

Should be:

else:
     df1["AVL"] = N_Sup - df1["DMD"]
             ^
here it is:--+

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dominique