asimo
asimo

Reputation: 2500

apply function does not populate the column with the values, rather populates everything as None

I have the below function which works well if i just do a print of the iv fucntion, and it shows the outputs appearing on my screen.

However if i run the apply function and try to populate the output in a new column, it just populates None. Can you advise what is missing here please

def myfunc(row):
    try:
        iv(row['Close_x'], row['Close_y'], row['Strike'], row['TTE_x'], 0.0, flag='c')  
    except BelowIntrinsicException as bie:
        print("bieError on row", row.name)
    except ZeroDivisionError as zde:
        print("zdeError on row", row.name)        
    except ValueError as ve:
        print("veError on row", row.name)          

df['IV_calls'] = df.apply(myfunc,axis=1)

Upvotes: 0

Views: 20

Answers (1)

Victor Guichard
Victor Guichard

Reputation: 71

Your function has no return statement, hence it returns None.

Upvotes: 2

Related Questions