【发布时间】:2020-10-14 16:55:36
【问题描述】:
我有一个由 1000 行组成的数据集,其中包含给定作者和属于该作者的大量文本语料库。我最终想要实现的是将文本行分解为包含相同数量单词的多行,如:
Author - - - - - - - - text
Jack - - - - - - -- - -"This is a sentence that contains eight words"
John - - - - - - - - -"This is also a sentence containing eight words"
因此,如果我想为 4 字块做这件事,那就是:
Author- - - - - - text
Jack- - - - - - - "This is a sentence"
Jack- - - - - - -"that contains eight words"
John- - - - - - - "This is also a"
John- - - - - - - "sentence containing eight words"
我已经可以使用 textwrapper 按字符数来完成,但理想情况下我想按字数来完成。 任何可以导致这一点的帮助将不胜感激, 谢谢!
【问题讨论】:
-
使用空格作为单词
string.split(" ")之间的分隔符。然后使用切片splitted_list[:]
标签: python pandas string split word