【发布时间】:2021-06-02 01:31:08
【问题描述】:
这个问题是这里的后续问题: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
出于某种原因,这并没有忽略这些警告。我试图忽略它们来自的熊猫的警告,而不是我可能从其他包中得到的警告。您能否告知为什么这不起作用?
【问题讨论】:
-
听警告并停止使用已弃用的代码不是更容易吗?
-
我们没有去月球,因为它很容易
-
我只想知道怎么做。我会修复代码,但为什么它不起作用?
标签: python python-3.x pandas warnings deprecation-warning