I am quite new to Python, I am trying to create a conditional column from the age data.
This is the code I entered. ( I have a df with a column named Age )
if Titanic['Age'] < 51:
Titanic['New_Age'] = 'Adult'
elif Titanic['Age'] < 19:
Titanic['New_Age'] = 'Teenager'
elif Titanic['Age'] < 14:
Titanic['New_Age'] ='Child'
elif Titanic['Age'] < 6:
Titanic['New_Age'] = 'Baby'
else:
Titanic['New_Age'] = 'Senior'
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Could someone help me please. The alternative plan is to import the data into PowerBI and use the conditional formatting there and export the csv.
Aucun commentaire:
Enregistrer un commentaire