I have the following list :
Training_Frame = pca.fit_transform(np_scaled_train)
with the following shape (2358,4)
I want to add a fifth column, This column is saved in a pandas dataframe, for that here what I've tried without any success :
Training_Frame.append(dataframe_train.iloc[:,-1])
AttributeError: 'numpy.ndarray' object has no attribute 'append'
So I've tried the following
saved_frame = np.append(Training_Frame,dataframe_train.iloc[:,-1])
# This works but the result has a weird shape `(11790,)` despite :
np.shape(dataframe_train.iloc[:,-1]) # is (2358,) so I'm expecting or hopping to get a shape like `(2358,5)
`
So I kind of don't get what's the issue here, any Idea how could I do this ?
np.appendis often misused. Learn to usenp.concatenateinstead.Training_Frameis not a DataFrame; it is a numpy array. You can convert it to a DataFrame withpd.DataFrame(Training_Frame).np.column_stack()...