Reputation: 25
The fill function is to fill all the non-available data in titanic with the average age of that particular class of passengers
titanic['Age']=titanic[['Age','Pclass']].apply(fill,axis=1)
sex=pd.get_dummies(titanic['Sex'],drop_first=True)
embarked=pd.get_dummies(titanic['Embarked'],drop_first=True)
titanic.drop(['Cabin','Embarked'],axis=1,inplace=True)
titanic.dropna(inplace=True)
titanic=pd.concat(['titanic','sex','embarked'],axis=1)
Upvotes: 0
Views: 6766
Reputation: 2424
I think you mean:
titanic=pd.concat([titanic,sex,embarked],axis=1)
instead of:
titanic=pd.concat(['titanic','sex','embarked'],axis=1)
A side note however:
If you're just trying to drop NaN
values and get dummies you can do it on the original dataframe without having to use pandas.concat.
example:
titanic = pd.get_dummies(titanic)
and just drop NaN values with dataframe.dropna:
titanic.dropna(inplace=True)
Hope this was helpful.
Upvotes: 1
Reputation: 30605
pd.concat expects you to give list of dataframe as parameter not a list of strings. Change your code to
titanic=pd.concat([titanic,sex,embarked],axis=1)
Upvotes: 2