Blue Week Special Offer | Brighten your week!

Deterimin_value function

I try to create a function to determine value for each question. Error showed, I dont understand why my code dont work. Could someone help with it?

Screen Link:

My Code:

def determin_value(row):
    for i in row['clean_value']:
        if i>800:
    return value

df['high_value'] = df.apply(determin_value, axis = 1)    

What I expected to happen:
my function works and returns a new column with a value 0 or 1

What actually happened:

TypeError: ("'int' object is not iterable", 'occurred at index 19325')
1 Like


You shouldn’t use the for-loop here: the argument row of your function is already a row, i.e. there is no need to iterate through rows (you will apply this fuction to each row of your dataframe through using axis=1 in the apply() method).

Instead, inside your function you should start directly with the if-statement:

if row["clean_value"] > 800:


I see! I was not thinking right!! Thank you!

1 Like