Использование pandas.DataFrame.values или pandas.DataFrame.to_numpy с numpy.reshape
По документации для панд: рекомендуется использовать DataFrame.to_numpy()
import numpy as np
import pandas as pd
import pandas as pd
list = [1,2,3,4,1,2,3,4,1,2,3,4]
df = pd.Series(list)
# Option1 using 'values' with reshape()
print('Option1 : \n', df.values.reshape(3,4).T)
# Option2 using 'to_numpy()' with reshape()
print('Option2 : \n',df.to_numpy().reshape(3,4).T)
# Get reshape dataframe to vector
df1 = pd.DataFrame(df.to_numpy().reshape(3,4).T)
# dataframe to vector Option1
print('Option1: Convert dataframe to vector: \n', np.reshape(df1.values.T, (1, df1.size)))
# dataframe to Option2
print('Option2: Convert dataframe to vector: \n', df1.to_numpy().T.reshape(1, df1.size))
# numpy array to vector :
df2 = df.to_numpy().reshape(3,4).T
print('Array to vector: \n', np.reshape(df2.T, (1, df2.size)))
Out:
Option1 :
[[1 1 1]
[2 2 2]
[3 3 3]
[4 4 4]]
Option2 :
[[1 1 1]
[2 2 2]
[3 3 3]
[4 4 4]]
Option1: Convert dataframe to vector:
[[1 2 3 4 1 2 3 4 1 2 3 4]]
Option2: Convert dataframe to vector:
[[1 2 3 4 1 2 3 4 1 2 3 4]]
Array to vector:
[[1 2 3 4 1 2 3 4 1 2 3 4]]
Смотрите здесь интерактив