首页 > 解决方案 > Python Pandas – 如何抑制 PerformanceWarning?

问题描述

如何抑制熊猫中的 PerformanceWarning?

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

标签: pythonpandassuppress-warnings

解决方案


PerformanceWarning 不是内置警告类,因此您不能直接在类别参数中调用它。您可以尝试以下代码:

import pandas as pd
import warnings

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

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


推荐阅读