The line sib, parch = passenger
assumes that passenger
has two elements, which you're trying to assign to sib
and parch
. The error is saying that two elements were expected (one for sib
, one for parch
), but that only one was supplied (passenger
).
If you're trying to apply accompany_alone()
across each row, it could be easier to just iterate over the row indices explicitly, for example something like this would work:
def accompany_alone(sib, arch):
if sib > 0: return 'With Family'
elif parch > 0: return 'With Family'
else: return 'Alone'
titanic_df['Alone'] = [accompany_alone(titanic_df['SibSp'][idx],
titanic_df['Parch'][idx])
for idx in range(titanic_df.shape[0])]
Also try playing around with the axis
parameter of DataFrame.apply()
-- it might not be behaving as you expect (here's a link to the docs).