-1

So I was not obtaining any syntax errors with the first if statement. When I add the second elif, i get a syntax error for the next line: NPI = df["NPI2"] ^ SyntaxError: invalid syntax

Not sure why this is happening since the first if statement is essentially the same as the elif

Here's my code:

for i, row in df.iterrows():
    NPI2 = row["NPI2"]
    
    if row["CapDesignation"] == "R" and row["BR"] >= row["CapThreshold"]:
        NPI2 = row["CapThreshold"]*row['KBETR']-.005
        df.at[i,"NPI2"] = NPI2
        df.at[i,"BR"] = NPI2/row["KBETR"]
    

    elif row["CapDesignation"] == "N" and row["BN"] >= row["CapThreshold"]:
        NPI2 = row["CapThreshold"]*(row["KBETR"]-row["P"])-.005
        df.at[i,"NPI2"] = NPI2
        df.at[i,"BN"] = NPI2/((row["KBETR"]-row["P"])
    


NPI = df["NPI2"]
df["KBETR_N"] = round(R + Delta_P + NPI,2)
  • 1
    Please provide sample data and in a [reproducible way](https://stackoverflow.com/questions/20109391). Otherwise people won't be able to test. – Bill Huang Apr 07 '21 at 06:40

1 Answers1

0

Not sure where the error is without the traceback message, but it should be: df.at[i,"BN"] = NPI2/((row["KBETR"]-row["P"]) where you have 2 parentheses in ((row["KBETR"] instead of 1(if you wish to have row["KBETR"]-row["P"] surrounded by parentheses).

timthedev07
  • 454
  • 1
  • 6
  • 17