【问题标题】:Python Pandas – How to supress PerformanceWarning?Python Pandas – 如何抑制 PerformanceWarning?
【发布时间】:2018-07-25 14:32:53
【问题描述】:

如何在 pandas 中抑制 PerformanceWarning?

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

【问题讨论】:

  • 你能试着把warnings.simplefilter(action='ignore', category=PerformanceWarning)放在import pandas前面吗?

标签: python pandas suppress-warnings


【解决方案1】:

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

import pandas as pd
import warnings

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

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

【讨论】:

  • 谢谢。有效!我有一个带有 pd.DateOffset() 操作的 PerformanceWarning。
猜你喜欢
  • 2019-10-05
  • 2017-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-20
  • 2019-04-02
  • 2018-12-05
  • 1970-01-01
相关资源
最近更新 更多