我有像下面这样的专栏
df =
idx text
0 i
1 am
2 a
3 boy
4 .
5 he
6 is
7 running
8
9 .
我想将其转换为纯文本并在.
句号之前删除空格,如下所示:
i am a boy. he is running.
我试过了,但还是没有成功。
如果需要删除一个或前多个空格.
使用.join
具有re.sub
:
import re
out = re.sub('\s+\.','.', ' '.join(df['text']))
或者:
import re
#https://stackoverflow.com/a/18878958/2901002
df = re.sub(r'\s+([.])', r'\1', ' '.join(df['text']))
print (df)
i am a boy. he is running.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句