dimanche 14 juin 2020

How to create a dataframe in which one column's input is dynamic and derived via an IF statement dependent on another entry in that column

I am looking to convert a two column Excel table which uses IF statements to calculate values in the second column, in to a Pandas dataframe.

enter image description here

Column A figures are static.

Column B figures are dynamic (with the exception of B5 which always remains 100%) and are calculated in Excel with the following IF statement (row 5 being the starting/reference point):

B4 =IF((B5*(1+Variable_1))<2, B5*(1+Variable_1), 2)

B3 =IF((B4*(1+Variable_1))<2, B4*(1+Variable_1), 2)

B2 =IF((B3*(1+Variable_1))<2, B3*(1+Variable_1), 2)

...and so on.

Variable_1 = a percentage (in this example 5%) which used when column A is negative.

When column A switches to positive i.e. >0% (A5), the IF statement changes to:

B6 =IF((B5*(1-Variable_2))>0, B5*(1-Variable_2), 0)

B7 =IF((B6*(1-Variable_2))>0, B6*(1-Variable_2), 0)

… and so on.

Variable_2 is also a percentage and is used when column B is positive (in this example it is also 5%).

I'm a complete amateur when it comes to Python but im hoping someone out there can assist me with something which is rather easy to do in Excel! Many thanks in advance.

Aucun commentaire:

Enregistrer un commentaire