【问题标题】:word cloud for expressions more than one word多于一个词的表达词云
【发布时间】:2022-11-08 18:02:54
【问题描述】:

我有一个包含一些字符串值的列的 excel 文件。其中一些价值不止一个词。例如,我有一个值为“心理健康”的单元格。但是当我创建词云时,它将它分成两个词。如果我想将每一列作为一个观察值,我该怎么办?

df = pd.read_csv(r"C:\Users\.......\jj.csv", encoding='utf8')
df = df["Outcome"]
our_mask = np.array(Image.open("C:\\Users\\.....\\baby.png"))

stopwords = set(STOPWORDS)

wc = WordCloud(background_color = "white", font_path='arial',
               colormap='Reds', random_state=1,repeat=True,
               collocations=False,
               max_words = 150,
               stopwords = stopwords,
               mask = our_mask,
               contour_width = 1,
               contour_color = 'Gray').generate(str(df))

#Plotting
plt.imshow(wc, interpolation = 'bilinear')
plt.axis('off')
plt.show()

【问题讨论】:

    标签: python


    【解决方案1】:

    为了解决这个问题,我首先使用 value_counts() 函数来获取我的“名称”值的频率。 然后我改变了我的代码如下......

    d = dict(zip(df["Name"], df["frequencies"]))
    wc = WordCloud(background_color = "white", font_path='arial',
                   colormap='prism', random_state=1,repeat=True,
                   collocations=False,
                   max_words = 2000,
                   stopwords = stopwords,
                   mask = our_mask,
                   contour_width = 1,
                   contour_color = 'red', width=1600, height=800).generate_from_frequencies(d)
    
    

    【讨论】:

      猜你喜欢
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 2017-11-30
      • 2022-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多