I'm looking to create a custom function based off several columns (
`TOTAL_HH_INCOME','HH_SIZE'
'Eligible Household Size', 'income_min1', 'income_max1', 'hh_size2','income_min2', 'income_max2', 'hh_size3', 'income_min3', 'income_max3', 'hh_size4', 'income_min4', 'income_max4', 'hh_size5', 'income_min5', 'income_max5', 'hh_size6', 'income_min6', 'income_max6'`
I'm looking to compare HH Size vs each HH size# variable and TOTAL_HH_INCOME vs every income_min & income_max variable for each row in my dataframe.
I've made this function as an attempt
def eligibility (row):
if df['HH_SIZE']== df['Eligible Household Size'] & df['TOTAL_HH_INCOME'] >= df['income_min1'] & df['TOTAL_HH_INCOME'] <=row['income_max1'] :
return 'Eligible'
if df['HH_SIZE']== df['hh_size2'] & df['TOTAL_HH_INCOME'] >= df['income_min2'] & df['TOTAL_HH_INCOME'] <=row['income_max2'] :
return 'Eligible'
if df['HH_SIZE']== df['hh_size3'] & df['TOTAL_HH_INCOME'] >= df['income_min3'] & df['TOTAL_HH_INCOME'] <=row['income_max3'] :
return 'Eligible'
if df['HH_SIZE']== df['hh_size4'] & df['TOTAL_HH_INCOME'] >= df['income_min4'] & df['TOTAL_HH_INCOME'] <=row['income_max4'] :
return 'Eligible'
if df['HH_SIZE']== df['hh_size5'] & df['TOTAL_HH_INCOME'] >= df['income_min5'] & df['TOTAL_HH_INCOME'] <=row['income_max5'] :
return 'Eligible'
if df['HH_SIZE']== df['hh_size6'] & df['TOTAL_HH_INCOME'] >= df['income_min6'] & df['TOTAL_HH_INCOME'] <=row['income_max6'] :
return 'Eligible'
return 'Ineligible'
As you can see if the row meets a condition I want the row to be labeled as "Eligible" if not it should be labeled 'Ineligible'
I applied this function to my df with
df['Eligibility']= df.apply(eligibility, axis=1)
However, i receive an error:
ValueError: ('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().', 'occurred at index 0')
Why? Is my function off the mark?
EDIT:
====================== DATAFRAME ===========================
