我正在试着摆脱SettingWithCopyWarning。
我的代码:
combineQueryandBookFiltered['positionId'] = combineQueryandBookFiltered['positionId'].astype('int64')
combineQueryandBookFiltered.loc['pnlValue'] = np.multiply(combineQueryandBookFiltered['pnlValue'], df_fxrate['fx_rate'])我尝试过的:
combineQueryandBookFiltered['positionId'] = combineQueryandBookFiltered['positionId'].astype('int64').copy()
combineQueryandBookFiltered.loc['pnlValue'] = np.multiply(combineQueryandBookFiltered['pnlValue'], df_fxrate['fx_rate'])控制台消息:
//stack/over/flow/code1.py:154: 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: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
combineQueryandBookFiltered['positionId'] = combineQueryandBookFiltered['positionId'].astype('int64').copy()
//stack/over/flow/code1:156: 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
combineQueryandBookFiltered.loc['pnlValue'] = np.multiply(combineQueryandBookFiltered['pnlValue'], df_fxrate['fx_rate'])有人可以帮助消除这些消息吗?
发布于 2019-10-01 02:10:33
在导入pandas之后,您可以尝试在代码的开头运行此代码:
pd.options.mode.chained_assignment = None然而,重要的是理解原因并解决它,而不是简单地抑制警告。你可以找到完整的解释here
https://stackoverflow.com/questions/58173045
复制相似问题