Was trying my hand at the Titanic dataset, when I wanted to One Hot Encode a categorical feature, after which I wanted to combine the original data with the new one hot vectors. The datatypes are as such:
data
: Pandas Dataframe
Titles_ohe
: Numpy sparse matrix (float64)
I tried to merge them into a dataframe using np.c_
:
columns = (list(data))+list(Titles.values)
data = pd.DataFrame(np.c_[data.values, Titles_ohe.toarray()], columns=columns)
However on checking the data type of the resulting Dataframe, all the attributes have been changed to the object
datatype. Is there any way I can prevent this while using np.c_
, or is there an alternative solution? Thanks in advance for any help!