While preparing the data (text file) for preprocessing. I am not able to split the text file into words.
准备数据(文本文件)进行预处理时。我无法将文本文件拆分为单词。
import io
f = io.open("pg5200.txt", mode="r", encoding="utf-8")
text = f.read()
f.close()
import re
words = re.split(r'\W+', text)
print(words[:100])
After using the above code: The problem is I am getting an extra blank space (" ") in the beginning.
使用上面的代码后:问题是我在开头有一个额外的空格(“”)。
May I know why this extra space is occurring and how can I remove it??
我可以知道为什么这个额外的空间正在发生,我该如何删除它?
Thank You
谢谢
1 个解决方案
#1
0
You can use the strip
function.
您可以使用条带功能。
Check this answer How do I trim whitespace?
检查此答案如何修剪空白?
#1
0
You can use the strip
function.
您可以使用条带功能。
Check this answer How do I trim whitespace?
检查此答案如何修剪空白?