I have a Pandas dataframe called 'training_set' that resembles the screenshot below:
I try to turn the 'label' column into array and transpose it. I tried doing Y_train=np.asarray(training_set['label'])
but what I got is a horizontal array that resembles the screenshot below, which is not what I want.
I want the array to display vertically just like the screenshot below (The screenshot has 2 variables per row. My desired output should only contain 1 variable, the 'label', per row.)
Any suggestion or help would be greatly appreciated!
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