Python Pandas – 如何抑制性能警告?

Python Pandas – How to supress PerformanceWarning?

如何在 pandas 中抑制 PerformanceWarning?

我已经尝试过 warnings.simplefilter(action='ignore', category=PerformanceWarning),但它给了我 NameError: name 'PerformanceWarning' is not defined

PerformanceWarning 不是内置警告 class 因此您不能在 category 参数中直接调用它。您可以试试下面的代码:

import pandas as pd
import warnings

warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)

我不知道如何重现 PerformanceWarning,但我测试了与“SettingWithCopyWarning”pandas 警告类似的方法并且它有效。让我知道它是否有效。