0

I'm a beginner in Python and I'm trying to assign numbers to different values in the same column using def and .apply but the entire column is being assigned only the first argument.

def encode_donor(x):
    if x == 'Control Old' or 'Control Young':
        return 0
    elif x == 'Young-fed Old' or 'Young-fed Young':
        return 1
    else:
        return 2

df['donor_status'] = df['donor_status'].apply(encode_donor)

I tried the above but every donor_status gets assigned 0, and I can't see where I've made the error. Any help would be greatly appreciated, thank you!

0 Answers0