简体   繁体   中英

How to assign Numpy array values to other variable

This is my code:

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

Output:

class 'numpy.ndarray'

class 'numpy.ndarray'

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

A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self._setitem_with_indexer(indexer, value)

Python just print the above output, and that's all. The program is technically running, but below code do not get executed, no real error is shown.

Error Line: y_pred.loc[i] = y_predForThisMatchType[count]

y_pred variable is a pandas dataframe.

Have you checked your outputs completely?
In my experience, your code is working.
The display is just a warning and can be disabled with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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