Pandas 1.5.3 中的SettingWithCopyWarning 不起作用

top*_*ntz 1 python warnings pandas pandas-settingwithcopy-warning

我知道有一些关于此的线程,但我在实际SettingWithCopyWarning本身上遇到了麻烦,所以它们都没有任何帮助。

我最近对我的机器进行了核攻击,并且正在重新安装 Pycharm 和所有库等。在运行我的一些脚本时,我不断收到与抑制SettingWithCopyWarning.

import warnings
from pandas.core.common import SettingWithCopyWarning
warnings.simplefilter(action="ignore", category=SettingWithCopyWarning)
Run Code Online (Sandbox Code Playgroud)

这些是我正在运行的行,它们会导致以下错误消息:

ImportError: cannot import name 'SettingWithCopyWarning' from 'pandas.core.common'
Run Code Online (Sandbox Code Playgroud)

我查看了该common.py文件,没有看到任何对SettingWithCopyWarning. 我使用的是 Python 3.8 和 Pandas 版本 1.5.3。

干杯

Cor*_*ien 5

使用pandas.errors.SettingWithCopyWarning

import warnings
from pandas.errors import SettingWithCopyWarning
warnings.simplefilter(action="ignore", category=SettingWithCopyWarning)
Run Code Online (Sandbox Code Playgroud)

我强烈建议您隐藏此警告。这可能会导致意外的副作用和错误

花时间阅读如何处理 Pandas 中的SettingWithCopyWarning