【问题标题】:Best way to take text from data frame, tokenize by sentence then by word从数据框中获取文本的最佳方法,按句子然后按单词进行标记
【发布时间】:2019-10-16 17:32:20
【问题描述】:

想从一个数据框中获取一个 cmets 列表,首先解析成一个句子列表,然后在第二次通过时,按单词解析。需要这个输入到 word2vec 模型,genism。

已经使用 nltk 中的 sent_tokenize 进行了一次标记化,但是如果我在那之后尝试 word_tokenize ,就会遇到问题,因为它不再是字符串,而是需要类似对象的字符串或字节。

import nltk

print(df)

ID Comment
0   Today is a good day.
1   Today I went by the river. The river also flow...
2   The water by the river is blue, it also feels ...
3   Today is the last day of spring; what to do to...

df['sentences']=df['Comment'].dropna().apply(nltk.sent_tokenize)

df['word']=df['sentences'].dropna().apply(nltk.word_tokenize)

在尝试将句子转换为单词之后 TypeError:预期的字符串或类似字节的对象

【问题讨论】:

标签: python nlp tokenize word2vec


【解决方案1】:
I guess the problem is as you have none null values so you can try

df['word']=df['sentences'].apply(nltk.word_tokenize)

【讨论】:

    猜你喜欢
    • 2012-07-19
    • 1970-01-01
    • 2013-09-25
    • 2019-05-12
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2016-10-03
    相关资源
    最近更新 更多