I am trying to recreate this function from excel in Python. I got the code to work for a single Port ID. When i let the rest in, it calculates all the port IDs.
# Function to calculate the fvschedule from excel
def calculate_fvschedule(p_value, ACCT_RETURN):
future_value = p_value
for return in ACCT_RETURN:
future_value *= (1 + rate)
return future_value
Only four headers in my data set.
Added fake date for context:
I want to do the same calculation for each port id. I assume I have to add an if statement to my for loop to look for the change but haven’t got it to work.
“if a = b” should produce a syntax error. What you want is “if a == b”.
You are comparing cur_port to itself…why? Comparison of a variable with itself will always == True.
“return” is a reserved name, that can’t be overwritten, and can’t be used as a temp variable in a for loop or anywhere as a variable, as far as I know.
The ValueError is caused by a Series object being checked for boolean, which isn’t occuring in this code snippte, so can’t advise.