我试图找出在同一个单词中有相同重复字符的句子,例如:
Sentence
are they saddddd?
I don't want to go
heyyyyy
12333
00unit
00wolf
01man
20595
2091996
03dumbdumb
若值1或0包含或不包含重复字符,则为其赋值(预期输出如下):
Sentence Lab
are they saddddd? 1
I don't want to go 0
heyyyyy 1
12333 1
00unit 0
00wolf 0
01man 0
20595 0
2091996 0
03dumbdumb 0
我尝试了以下方法:
df.loc[(df['Sentence'].str.findall(r'([a-zA-Z])\1{3}').astype(bool)), 'Lab']=1
但是,无论至少3个相同字符是否连续,它都无法正确指定值1
你能看一下我的代码并告诉我为什么它不工作吗
有些值,如00unit, 00wolf, 01man, 20595, 2091996, 03dumbdumb
,从上面的代码中错误地选择,因为它们包含三个相同的连续字符,而它们没有
模式是任何单词字符后跟至少两个以上的字符
或者
pattern = r'(([a-zA-Z0-9])\2{2,})'
如果不想匹配下划线将
\d
放入字符列表,并将{3}
更改为{2,}
如何:输出:
相关问题 更多 >
编程相关推荐