lundi 1 juillet 2019

Is there a way to compare values of one column and then update a list based on if a condition is met?

I have a data frame of datetimes, pay, and duration. Duration is the difference between the two datetime columns and pay is what I paid a provider to complete a service.I'm trying to iterate through the each value in the column 'duration' and if the value is >= 100 then add to the list newPrice a value which is the corresponding value in the payColumn*.99

I have tried building nested if/for loops, lambda statements, and building my own function. I'm transitioning from R to Python in my job and am not doing well at the moment to translate this process into Python code.

` duration = [122.0, 48.0, 102.0] Pay = [50.00, 26.49, 36.80] newPay = []

for i in df['duration']:
     if i >= 100:
          newPay.append(df['Pay']*.99)
     elif i >= 50 and i <= 99.99:
          newPay.append(df['Pay']*.98)
     else:
          newPay.append(df['Pay']*.97)
print(newPay)

`

I expect newPay to be populated with the original pay multiplied by the modifier

Aucun commentaire:

Enregistrer un commentaire