vendredi 1 décembre 2017

Couldn't make a new column from the data provided within the data frame

I'm trying to add the column in titanic data frame using apply function. However, I'm getting an error where the function is defined. I also tried applying .all(), .any() but I couldn't get the correct answer. What is the way to solve it?

titanic = sns.load_dataset('titanic')
titanic.head()

titanic['With(out)'] = titanic.sibsp + titanic.parch

def alone(n):
    if titanic['With(out)'] > 0:
        return 'With Family'
    else: 
        return 'Alone'

titanic['Alone'] = titanic['With(out)'].apply(alone)

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Aucun commentaire:

Enregistrer un commentaire