Creating new columns in "Challenge: Cleaning Data"

def clean_deaths(row):
num_deaths = 0
cols = [‘Death1’, ‘Death2’, ‘Death3’, ‘Death4’, ‘Death5’]

for c in cols:
    death = row[c]
    if pd.isnull(death) or death == 'NO':
    elif death == 'YES':
        num_deaths += 1
return num_deaths

true_avengers[‘Deaths’] = true_avengers.apply(clean_deaths,axis=1)

The code above is for creating a new column called Deaths where it will have info from other death columns. The part that I am confused about it having the parameter ‘row’ in the clean_death function and using the ‘row’ in the for loop. What role is this ’ row’ playing.

Thank you and have a great day.

row is the argument you’re passing into the the function — when you apply a function to a df, like what you’re doing here, it automatically iterates over each row in the df. So, in this case, row quite literally means each row in the df.

Hope that makes sense!