Home > OS >  Why is the "else" line giving an invalid syntax error even with proper indentation and syn
Why is the "else" line giving an invalid syntax error even with proper indentation and syn

Time:09-17

I know this question has been asked many many times on here, but I seem to not have the same issues as others. I continually get "syntax error invalid syntax else", but do not know why this is. I seem to have everything properly indented and colons after the else statement. Any help would be much appreciated. Thanks

def normalization (fname, attr, normType):
    result = {}
     
    df = pd.read_csv(fname)
    targ = list(df[df.columns[attr]])
    scaler = MinMaxScaler()
     
    df["minmax"] = scaler.fit.transform(df[[df.columns[attr]]])
    
    df["zscore"] = ((df[[df.columns[attr]]]) - (df[[df.columns[attr.mean()]]]))/(df[[df.columns[attr.std(ddof=1)]]])
    

    if normType == "min_max":
        result = dict(zip(targ, df.minmax.values.tolist())
    
                  
    else:
        result = dict(zip(targ, df.zscore.values.tolist())
        
                                                
    return result

CodePudding user response:

result = dict(zip(targ, df.minmax.values.tolist()))

The conversion to dictionary line in the if condition is missing one bracket.

  • Related