如何解决忽略 Python pandas 中的 FutureWarnings
这个问题是从这里的后续: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
出于某种原因,这并没有忽略这些警告。我试图忽略它们来自熊猫的警告,而不是我可能从其他包中得到的警告。你能告诉我为什么这不起作用吗?
解决方法
根据我的小调查,pandas 似乎有一些棘手的方法。你试过import warnings; warnings.filterwarnings("ignore")
吗?
您也可以查看此 thread。如果警告仍然存在,就让它过去吧,它不会阻止您的代码运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。