当我运行程序时,Pandas每次都给出如下所示的“未来警告”。
D:\Python\lib\site-packages\pandas\core\frame.py:3581: FutureWarning: rename with inplace=True will return None from pandas 0.11 onward
" from pandas 0.11 onward", FutureWarning)
我得到了消息,但我只是想阻止Pandas一次又一次地显示这样的消息,是否有任何buildin参数我可以设置让Pandas不会弹出'Future warning'?
在github上找到了...
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
@ bdiamante的回答可能只对您有所帮助。如果您在抑制警告后仍然收到消息,那是因为pandas
库本身正在打印消息。除非您自己编辑Pandas源代码,否则您无能为力。也许内部有一个选项来压制它们,或者是一种覆盖事物的方法,但我找不到一个。
假设您要确保干净的工作环境。在脚本的顶部,你放了pd.reset_option('all')
。使用Pandas 0.23.4,您可以获得以下信息:
>>> import pandas as pd
>>> pd.reset_option('all')
html.border has been deprecated, use display.html.border instead
(currently both are identical)
C:\projects\stackoverflow\venv\lib\site-packages\pandas\core\config.py:619: FutureWarning: html.bord
er has been deprecated, use display.html.border instead
(currently both are identical)
warnings.warn(d.msg, FutureWarning)
: boolean
use_inf_as_null had been deprecated and will be removed in a future
version. Use `use_inf_as_na` instead.
C:\projects\stackoverflow\venv\lib\site-packages\pandas\core\config.py:619: FutureWarning:
: boolean
use_inf_as_null had been deprecated and will be removed in a future
version. Use `use_inf_as_na` instead.
warnings.warn(d.msg, FutureWarning)
>>>
按照@ bdiamante的建议,你使用warnings
库。现在,说实话,警告已被删除。但是,仍然存在一些令人讨厌的消息:
>>> import warnings
>>> warnings.simplefilter(action='ignore', category=FutureWarning)
>>> import pandas as pd
>>> pd.reset_option('all')
html.border has been deprecated, use display.html.border instead
(currently both are identical)
: boolean
use_inf_as_null had been deprecated and will be removed in a future
version. Use `use_inf_as_na` instead.
>>>
实际上,禁用所有警告会产生相同的输出:
>>> import warnings
>>> warnings.simplefilter(action='ignore', category=Warning)
>>> import pandas as pd
>>> pd.reset_option('all')
html.border has been deprecated, use display.html.border instead
(currently both are identical)
: boolean
use_inf_as_null had been deprecated and will be removed in a future
version. Use `use_inf_as_na` instead.
>>>
在标准库意义上,这些不是真正的警告。熊猫实施自己的警告系统。在警告消息上运行grep -rn
表明pandas
警告系统在core/config_init.py
中实现:
$ grep -rn "html.border has been deprecated"
core/config_init.py:207:html.border has been deprecated, use display.html.border instead
进一步的追逐表明我没时间做这件事。而且你可能也没有。希望这可以帮助您避免陷入兔子洞或者激励某人弄清楚如何真正压制这些消息!