vendredi 26 novembre 2021

Python and Excel: convert an If function from excel to Python

I have an IF function from excel which looks like this:

=WENN('Efficiency Wages'!B2>'Living Wages'!B2;'Efficiency Wages'!B2;"")

("Wenn" means "if" - its german)

So basically if a value of B2 from sheet "Efficiency Wages" is higher than the value of B2 from sheet "Living Wages" then value should be the B2 value from Efficiency Wages. If not than then the cell should be blank. This function is written in another sheet called "new sheet".

My problem: how can i write this IF function in Python? I know that I can start with this:

if ws2.cell(row=2, column= 2).value > ws1.cell(row=2, column= 2).value:
    ws3.cell(row=2, column= 2).value = ws2.cell(row=2, column= 2).value

But i dont only want the function for cell B2. It should be a loop because this function goes for 12 columns and 52 rows.

Aucun commentaire:

Enregistrer un commentaire