忽略熊猫警告

时间:2016-02-03 11:35:21

标签: python pandas warnings

some similar questions,但那里的回复对我不起作用。

我正在尝试这样做,如warnings documentation

中所述
def disable_pandas_warnings():
    import warnings
    warnings.resetwarnings()  # Maybe somebody else is messing with the warnings system?
    warnings.filterwarnings('ignore')  # Ignore everything
    # ignore everything does not work: ignore specific messages, using regex
    warnings.filterwarnings('ignore', '.*A value is trying to be set on a copy of a slice from a DataFrame.*')
    warnings.filterwarnings('ignore', '.*indexing past lexsort depth may impact performance*')

我在测试/程序开始时调用它:

disable_pandas_warnings()

正如您在评论中所看到的,我有:

  • 确保警告过滤器不会被污染(因为过滤是在第一次匹配的情况下执行的)
  • 忽略所有消息
  • 忽略特定消息(通过提供消息正则表达式)

似乎没有效果:消息仍然显示。如何禁用所有警告?

0 个答案:

没有答案