忽略Python中的未来警告

2024-09-28 13:16:19 发布

您现在位置:Python中文网/ 问答频道 /正文

这个问题是这里的后续问题:How to disable Python warnings? 我有以下代码:

from prettytable import PrettyTable 
import operator
import calendar
import warnings
with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    warnings.filterwarnings("ignore", category=FutureWarning)
    import pandas as pd, datetime, calendar
...
{rest of my code}

我试图压制这些警告:

<ipython-input-3-7e458c7b53b6>:22: FutureWarning: weekofyear and week have been deprecated, please use DatetimeIndex.isocalendar().week instead, which returns a Series.  To exactly reproduce the behavior of week and weekofyear and return an Index, you may call pd.Int64Index(idx.isocalendar().week)
  data['week'] = data.index.week

出于某种原因,这并不是忽略这些警告。我试图忽略熊猫产地的警告,而不是我可能从其他包装中得到的警告。你能告诉我为什么这不起作用吗


Tags: andofimport警告datacalendarpdignore
1条回答
网友
1楼 · 发布于 2024-09-28 13:16:19

从我的小研究来看,熊猫似乎有一些巧妙的方法。你试过import warnings; warnings.filterwarnings("ignore")

您也可以检查此thread。如果警告持续存在,就随它去吧,它不会阻止代码运行

相关问题 更多 >

    热门问题