How to turn a Pandas column into array and transpose it?
Another way would be to reshape your array to shape (-1,1)
, which means "infer number of rows, force to 1 column":
Y_train = np.array(training_set['label']).reshape(-1,1)
One way:
Y_train = training_set['label'].values[:, None]
pandas >= 0.24
Use DataFrame.to_numpy()
, the new Right Way to extract a numpy array:
training_set[['label']].to_numpy()
pandas < 0.24
Slice out your column as a single columned DataFrame
(using [[...]]
), not as a Series
:
Y_train = np.asarray(training_set[['label']])
Or,
Y_train = training_set[['label']].values