Python 我怎样才能让一片片的文字一起出现?

Python 我怎样才能让一片片的文字一起出现?,python,word-cloud,Python,Word Cloud,编辑“请仅关注以下示例中的答案,没有广泛的场景” 嗯。我读过云这个词。但我想知道如何表示字符串变量中最频繁出现的单词,如下面的示例所示: Var_x wireless problems, migration to competitor dissatisfied customers, technicians visits scheduled call waiting, technicians visits bad customer experience, wireless problems 所以

编辑“请仅关注以下示例中的答案,没有广泛的场景”

嗯。我读过云这个词。但我想知道如何表示字符串变量中最频繁出现的单词,如下面的示例所示:

Var_x
wireless problems, migration to competitor
dissatisfied customers, technicians visits scheduled
call waiting, technicians visits
bad customer experience, wireless problems

所以我想要的是:(“无线问题”和“技术人员访问”)云中的表示。如何做到这一点?

此代码生成相邻单词的频率分布,可用作底层单词云数据:

from nltk import bigrams, FreqDist
from nltk.tokenize import RegexpTokenizer
from operator import itemgetter

sent = 'wireless problems, migration to competitor\n\
dissatisfied customers, technicians visits scheduled\n\
call waiting, technicians visits\n\
bad customer experience, wireless problems'

tokenizer = RegexpTokenizer(r'\w+')
sent_words = tokenizer.tokenize(sent)
freq_dist = FreqDist(bigrams(sent_words))

for k,v in sorted(freq_dist.items(), key=itemgetter(1), reverse=True):
    print(k,v)
输出

('technicians', 'visits') 2
('wireless', 'problems') 2
('dissatisfied', 'customers') 1
('bad', 'customer') 1
('scheduled', 'call') 1
('competitor', 'dissatisfied') 1
('migration', 'to') 1
('to', 'competitor') 1
('visits', 'scheduled') 1
('call', 'waiting') 1
('problems', 'migration') 1
('waiting', 'technicians') 1
('customers', 'technicians') 1
('customer', 'experience') 1
('experience', 'wireless') 1
('visits', 'bad') 1

此代码生成相邻单词的频率分布,这些单词可用作基础单词云数据:

from nltk import bigrams, FreqDist
from nltk.tokenize import RegexpTokenizer
from operator import itemgetter

sent = 'wireless problems, migration to competitor\n\
dissatisfied customers, technicians visits scheduled\n\
call waiting, technicians visits\n\
bad customer experience, wireless problems'

tokenizer = RegexpTokenizer(r'\w+')
sent_words = tokenizer.tokenize(sent)
freq_dist = FreqDist(bigrams(sent_words))

for k,v in sorted(freq_dist.items(), key=itemgetter(1), reverse=True):
    print(k,v)
输出

('technicians', 'visits') 2
('wireless', 'problems') 2
('dissatisfied', 'customers') 1
('bad', 'customer') 1
('scheduled', 'call') 1
('competitor', 'dissatisfied') 1
('migration', 'to') 1
('to', 'competitor') 1
('visits', 'scheduled') 1
('call', 'waiting') 1
('problems', 'migration') 1
('waiting', 'technicians') 1
('customers', 'technicians') 1
('customer', 'experience') 1
('experience', 'wireless') 1
('visits', 'bad') 1

使用各种库中的一个库或反驳为什么否决?您的问题很广泛,所以我假设这就是为什么-我没有否决它-或者因为如果您查看我链接的sklearn选项,然后查看文档,您将看到您可以设置ngram的“N”。意思是在你的案例中将其设置为bigrams使用各种库中的一个或反驳为什么否决?你的问题很广泛,所以我假设这就是为什么-我没有否决它-或者因为如果你查看我链接的sklearn选项,然后查找文档,你会看到你可以设置ngram的“N”。意思是在你的案例中将其设置为bigrams谢谢,我如何绘制这样的数据?看看这篇四年前的博文:。相应的更新代码位于github上的以下位置:。此库是github上目前最流行的python word cloud库,但如果它不适合您的需要,还有其他库。也可以查看此帖子,了解一些使用
word\u cloud
制作的非常出色的word cloud:谢谢,我已经看过了。但是它会生成单字云,我想要基于你为2个单词频率创建的输出的云。你能将每个两个单词元组连接成单个单词并通过
word\u cloud
运行它们吗?谢谢,我如何绘制这样的数据?看看四年前的这篇博文:。相应的更新代码位于github上的以下位置:。此库是github上目前最流行的python word cloud库,但如果它不适合您的需要,还有其他库。也可以查看此帖子,了解一些使用
word\u cloud
制作的非常出色的word cloud:谢谢,我已经看过了。但是它会生成单字云,我希望云基于您为2个单词频率创建的输出。您可以将每个两个单词元组连接成单字,并通过
word\u-cloud
运行它们吗?