这里主要讲解 argsort 排序这个函数,
来源于:numpy.argsort
pandas继承于numpy:pandas.Series.argsort
from sklearn.model_selection import train_test_split
#这里train_test_split返回的都是<class 'pandas.core.series.Series'>
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1, train_size=0.8)
order = y_test.argsort(axis=0)#获取顺序
print('type of order:', type(order))
print('content of order:', order)
print('type of y_test: ',type(y_test))
print('y test before sort:',y_test)
y_test = y_test.values[order]#对y_test进行排序
print('y test after sort:', y_test)
#对x_test进行排序,由于x_test为矩阵,所以使用[order,:]
x_test = x_test.values[order, :]