【发布时间】:2020-05-15 08:55:39
【问题描述】:
我正在尝试将数据帧输入到我的文字处理器中,以先拆分成句子,然后再拆分成单词。
示例文本:
When the blow was repeated,together with an admonition in
childish sentences, he turned over upon his back, and held his paws in a peculiar manner.
1) This a numbered sentence
2) This is the second numbered sentence
At the same time with his ears and his eyes he offered a small prayer to the child.
Below are the examples
- This an example of bullet point sentence
- This is also an example of bullet point sentence
所需输出
[
['When', 'the', 'blow', 'was', 'repeated', ',', 'together', 'with', 'an', 'admonition', 'in', 'childish', 'sentences', ',', 'he', 'turned', 'over', 'upon', 'his', 'back', ',', 'and', 'held', 'his', 'paws', 'in', 'a', 'peculiar', 'manner', '.'],
['1', ')', 'This', 'a', 'numbered', 'sentence']
['2', ')', 'This', 'is', 'the', 'second', 'numbered', 'sentence']
['At', 'the', 'same', 'time', 'with', 'his', 'ears', 'and', 'his', 'eyes', 'he', 'offered', 'a', 'small', 'prayer', 'to', 'the', 'child', '.']
['Below', 'are', 'the', 'examples']
['-', 'This', 'an', 'example', 'of', 'bullet', 'point', 'sentence']
['-', 'This', 'also','an', 'example', 'of', 'bullet', 'point', 'sentence']
]
到目前为止我尝试过的代码
from nltk.tokenize import RegexpTokenizer
tokenizer = RegexpTokenizer(r'[^d\)\-\*?!]+')
df["Regexp"] = data[comments].apply(tokenizer.tokenize)
【问题讨论】:
标签: python pandas dataframe nltk tokenize