Python 将列从列车中的预测复制到新列 X\u列车['预测等级]=y\u列车 foodData=pd.merge(foodData,X_列) :1:设置为带有CopyWarning: 试图在数据帧切片的副本上设置值。 尝试改用.loc[row\u indexer,col\u indexer]=value 请参阅文档中的注意事项:https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view vs-a-copy X_系列[‘预测评级’]=y_系列_预测

Python 将列从列车中的预测复制到新列 X\u列车['预测等级]=y\u列车 foodData=pd.merge(foodData,X_列) :1:设置为带有CopyWarning: 试图在数据帧切片的副本上设置值。 尝试改用.loc[row\u indexer,col\u indexer]=value 请参阅文档中的注意事项:https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view vs-a-copy X_系列[‘预测评级’]=y_系列_预测,python,pandas,Python,Pandas,试图将预测序列中的数据复制到X_序列中的新预测列中,但结果出现错误。在这种情况下,如何复制列而不弹出此错误?这不是错误,而是警告。 X_train['Predicted Ratings'] = y_train_pred foodData2 = pd.merge(foodData, X_train) <ipython-input-30-09a52c23fbdf>:1: SettingWithCopyWarning: A value is trying to be set on a

试图将预测序列中的数据复制到X_序列中的新预测列中,但结果出现错误。在这种情况下,如何复制列而不弹出此错误?

这不是错误,而是警告。
X_train['Predicted Ratings'] = y_train_pred

foodData2 = pd.merge(foodData, X_train)

<ipython-input-30-09a52c23fbdf>:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  X_train['Predicted Ratings'] = y_train_pred