gpt4 book ai didi

python - future 警告 : The default value of regex will change from True to False in a future version

转载 作者:行者123 更新时间:2023-12-04 05:09:15 28 4
gpt4 key购买 nike

我正在运行下面的代码来清理文本

import pandas as pd

def not_regex(pattern):
return r"((?!{}).)".format(pattern)

tmp = pd.DataFrame(['No one has a European accent either @',
'That the kid reminds me of Kevin'])

tmp[0].str.replace(not_regex('(\\b[-/]\\b|[a-zA-Z0-9])'), ' ')
然后它返回一个警告
<ipython-input-8-ef8a43f91dbd>:9: FutureWarning: The default value of regex will change from True to False in a future version.
tmp[0].str.replace(not_regex('(\\b[-/]\\b|[a-zA-Z0-9])'), ' ')
你能详细说明这个警告的原因吗?

最佳答案

Pandas 1.2.0 release notes :

The default value of regex for Series.str.replace() will change from True to False in a future release. In addition, single character regular expressions will not be treated as literal strings when regex=True is set (GH24804)


即,现在明确使用正则表达式:
dframe['colname'] = dframe['colname'].str.replace(r'\D+', regex=True)

关于python - future 警告 : The default value of regex will change from True to False in a future version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66603854/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com