【发布时间】:2020-05-30 16:52:26
【问题描述】:
我正在寻找有关 NLTK 的帮助,或者任何其他可以帮助我解决我面临的问题的库。
我不是 Python 专家(实际上我是 4 个月前才开始学习 Python),但在寻求帮助之前我已经做了一些研究:
Tokenizing words into a new column in a pandas dataframe
Passing a pandas dataframe column to an NLTK tokenizer 等等……
这就是我所拥有的:一个数据框,其中包含很多关于我们的学生在我们的网站上搜索信息时所寻找的信息(它是校园网站)。
看起来有点像这样:
session | student_query
2020-05-15 09:34:21 | exams session june 2020
2020-05-15 09:41:12 | when are the exams?
2020-05-15 09:59:51 | exams.
2020-05-15 10:02:18 | what's my teacher's email address
我想要的是一个看起来像的大列表: ['query', 'exams', 'session', 'june', '2020', 'when', 'are', 'the', Exams', 'exams', 'what', 's' , '我的', '老师', 's', 'email', '地址] ===> 一串,所有单词(无句子),无标点符号。
我试过了:
tokens = df['query'].apply(word_tokenize)
text = nltk.Text(tokens)
===> 为每行提供一个单独的字符串
sentences = pd.Series(df.Name)
sentences = sentences.str.replace('[^A-z ]','').str.replace(' +',' ').str.strip()
splitwords = [ nltk.word_tokenize( str(sentence) ) for sentence in sentences ]
print(splitwords)
===>好一点,但也不是我想要的
【问题讨论】: