这个问题是这里的后续问题: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
出于某种原因,这并不是忽略这些警告。我试图忽略熊猫产地的警告,而不是我可能从其他包装中得到的警告。你能告诉我为什么这不起作用吗
从我的小研究来看,熊猫似乎有一些巧妙的方法。你试过
import warnings; warnings.filterwarnings("ignore")
吗您也可以检查此thread。如果警告持续存在,就随它去吧,它不会阻止代码运行
相关问题 更多 >
编程相关推荐