小编Pyt*_*bie的帖子

在 pandas 数据框中形成单词的二元组

我一直在尝试将包含已标记化单词的 pandas 数据框转换为二元组,但我没有成功。我尝试了多个代码,但我要么不断收到错误消息,要么收到奇怪的答案。我大约两周前才开始使用 python,我真的很挣扎。任何帮助,将不胜感激。谢谢

这是我到目前为止所尝试过的。

from nltk.util import ngrams

generic_tweets['bigrams'] = generic_tweets['tweet'].apply(lambda row: list(map(lambda x:ngrams(x,2), row)))   
generic_tweets['bigrams'].head()
Run Code Online (Sandbox Code Playgroud)

在哪里

generic_tweets['tweet'].head() 

0         [awww, thats, bummer, shoulda, got, david, car...
1         [upset, that, he, cant, update, his, facebook,...
2         [dived, many, time, ball, managed, save, rest,...
3            [whole, body, feel, itchy, like, it, on, fire]
4         [no, it, not, behaving, at, all, im, mad, why,...
5                                        [not, whole, crew]
6                                               [need, hug]

Run Code Online (Sandbox Code Playgroud)

我想要的是

0         [(awww, thats), (thats, bummer), (bummer, shoulda)...
1         [(upset, that), …
Run Code Online (Sandbox Code Playgroud)

python nltk n-gram pandas

4
推荐指数
1
解决办法
8357
查看次数

标签 统计

n-gram ×1

nltk ×1

pandas ×1

python ×1