Python 熊猫数据帧从as_矩阵移动到_numpy

Python 熊猫数据帧从as_矩阵移动到_numpy,python,python-3.x,amazon-sagemaker,Python,Python 3.x,Amazon Sagemaker,这是我的密码: def predict(data, rows=500): split_array = np.array_split(data, int(data.shape[0] / float(rows) + 1)) predictions = '' for array in split_array: predictions = ','.join([predictions, xgb_predictor.predict(array).decode('utf

这是我的密码:

def predict(data, rows=500):
    split_array = np.array_split(data, int(data.shape[0] / float(rows) + 1))
    predictions = ''
    for array in split_array:
        predictions = ','.join([predictions, xgb_predictor.predict(array).decode('utf-8')])

    return np.fromstring(predictions[1:], sep=',')

data_test["predictions"]= predict(data_test.as_matrix()[:, 1:])
xgb_预测器是Sagemaker模型对象

由于不支持as_matrix(),因此不再有效


如何将其替换为to numpy()?

假设
数据\u test
是一个pandas矩阵,那么您应该能够直接使用
to numpy()

见:

DataFrame.values()


假设
data\u test
是一个pandas矩阵,那么您应该能够直接使用
to\u numpy()

见:

DataFrame.values()


我想出来了,下面是用于_numpy()的新代码


我想出来了,下面是用于_numpy()的新代码

Deprecated since version 0.23.0: Use DataFrame.values() instead.
We recommend using DataFrame.to_numpy() instead.
 def predict(data, rows=500):
        split_array = np.array_split(data, int(data.shape[0] / float(rows) + 1))
        predictions = ''
        for array in split_array:
            predictions = ','.join([predictions, xgb_predictor.predict(array).decode('utf-8')])
    
        return np.fromstring(predictions[1:], sep=',')
    #replace data_test["predictions"]= predict(data_test.as_matrix()[:, 1:]) with
    data_results["predictions"] =  predict(data_test.iloc[:,1:].to_numpy())