繁体   English   中英

如何将Numpy数组值分配给其他变量

[英]How to assign Numpy array values to other variable

这是我的代码:

y_predForThisMatchType = model.predict(X_test, num_iteration=model.best_iteration)
print(type(y_predForThisMatchType))
y_predForThisMatchType = y_predForThisMatchType.reshape(-1)
print(type(y_predForThisMatchType))

count = 0
for i in range (len(y_pred)):
    if y_pred.loc[i]  == abType:
        y_pred.loc[i] = y_predForThisMatchType[count]
        count = count + 1

输出:

类'numpy.ndarray'

类'numpy.ndarray'

/opt/conda/lib/python3.6/site-packages/pandas/core/indexing.py:189:SettingWithCopyWarning:

试图在DataFrame的切片副本上设置一个值

请参阅文档中的警告: http ://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self._setitem_with_indexer(索引器,值)

Python只是打印上面的输出,仅此而已。 该程序在技术上正在运行,但是下面的代码未执行,未显示实际错误。

错误线: y_pred.loc[i] = y_predForThisMatchType[count]

y_pred变量是一个熊猫数据y_pred

您是否已经完全检查了输出?
以我的经验,您的代码正在运行。
该显示仅是警告,可以通过以下方式禁用:

pandas.options.mode.chained_assignment = None  # default='warn'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM