pandas.errors.SettingWithCopyError#

exception pandas.errors.SettingWithCopyError[源代码]#

尝试在 DataFrame 的副本切片上设置值时引发的异常。

此时 mode.chained_assignment 需要设置为 ‘raise’。当发生链式索引时,这可能无意中发生。

有关求值顺序的更多信息,请参阅 the user guide

For more information on view vs. copy, see the user guide.

Examples

>>> pd.options.mode.chained_assignment = 'raise'
>>> df = pd.DataFrame({'A': [1, 1, 1, 2, 2]}, columns=['A'])
>>> df.loc[0:3]['A'] = 'a' 
... # SettingWithCopyError: A value is trying to be set on a copy of a...