SettingWithCopyWarning, используя loc - PullRequest
       9

SettingWithCopyWarning, используя loc

0 голосов
/ 30 сентября 2019

Я пытаюсь избавиться от 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'])

Кто-нибудь может помочь устранить эти сообщения?

1 Ответ

0 голосов
/ 30 сентября 2019

Вы можете попробовать запустить это в начале вашего кода, сразу после импорта pandas:

pd.options.mode.chained_assignment = None

Однако важно понять причину и решить ее, вместо того, чтобы просто подавить предупреждение,Вы можете найти полное объяснение здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...