python – 为什么我不能使用warnings.filterwarnings使用正则表
发布时间:2020-12-20 13:13:51 所属栏目:Python 来源:网络整理
导读:我想使用正则表达式来抑制特定类型的警告. 警告信息是: C:Anaconda3libsite-packagespandascoreindexing.py:420: SettingWithCopyWarning:A value is trying to be set on a copy of a slice from a DataFrame.Try using .loc[row_indexer,col_indexe
我想使用正则表达式来抑制特定类型的警告.
警告信息是: C:Anaconda3libsite-packagespandascoreindexing.py:420: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self.obj[item] = s 我的抑制过滤器的方式: import warnings warnings.filterwarnings("ignore",message= ".*A value is trying to.*") 然而,它失败了.我确实尝试将警告消息的不同部分粘贴到正则表达式中但仍然失败.我想知道为什么. 解决方法
这是你得到的错误吗?
AssertionError: message must be a string warnings.filterwarnings只接受message参数的字符串,regex不会在那里编译.如果您确实想要抑制此错误,请执行以下操作: import pandas as pd warnings.simplefilter("error",pd.core.common.SettingWithCopyWarning) 否则,您可能想要查看避免SettingWithCopyWarning的方法,因为许多其他人已经解决了同样的问题: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 有没有办法检查Twitch流是否使用Python?
- Python科学计算环境推荐――Anaconda
- python 之路,Day11 - sqlalchemy ORM
- python – Heroku的新手 – “没有像web这样的类型”
- python开发_IDEL(Python GUI)的使用方法
- SyntaxError: Non-ASCII character '?' in file
- python 处理dataframe中的时间字段方法
- python – 使用Tensorflow TF-Slim而不使用slim.learning.t
- Python解惑之True和False详解
- Python使用django搭建web开发环境