Skip to content
Advertisement

python for loop with if statement to divide numbers

if statement and for loop

I am stuck with the following code, I have a column in which I want to divide by 2 if the number is above 10 and run this for all the rows. I have tried this code but it gives the error of the series is ambiguous:

JavaScript

I suppose that I need a for loop in combination with the if statement. However I could not make it running, anyone has some ideas?

Advertisement

Answer

The easiest approach, I think, is to use boolean indexing. For example:

JavaScript

Result:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement