python - 如何为 Pandas Dataframe 中的每一列绘制 Wordlcoud?
问题描述
我有一个带有 N 行的熊猫数据框。
每行 N 有很多单词。
我正在尝试为每一列绘制 wordloud。
东风:
prediction text
0 1 [menu, food, food and chicken...
1 2 [transfer, money, transfer, transfer, trans...
2 0 [cold,cold,cold,hot,love...
代码
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
def show_wordcloud(data, title):
wordcloud = WordCloud(
background_color='white',
max_words=200,
max_font_size=40,
scale=3,
).generate(str(data))
fig = plt.figure(1, figsize=(12, 12))
plt.axis('off')
if title:
fig.suptitle(title, fontsize=20)
fig.subplots_adjust(top=2.3)
plt.imshow(wordcloud)
plt.savefig('cluster{}.png'.format(title))
plt.show()
for row in df.iterrows():
show_wordcloud(row['text'], row["prediction"])
但我得到的是除 lat 之外的所有列的空白图像。
我该如何解决?
谢谢
解决方案
推荐阅读
- django - 如何在 django 中从一个应用程序向另一个应用程序发出通知?
- flutter - 当我启动时,第一页(Dart 文件)将在 Flutter App 中运行
- reactjs - 优化 reactjs 中的拖动单元格表?
- r - 比较两条曲线的趋势差异
- openmpi - abinit 中的字符串方法教程 - 未生成输出文件
- python - 如何读取我的 exel 表中的特定数据并从读取的每个数据集创建一个图?(Python)
- java - Adler32 生成的校验和与 .txt 文件校验和不匹配
- python - Python:根据匹配从列表中写入文件
- angular - 如何在 Angular 中正确配置路由
- excel - 交互式 Excel 图表:根据下拉选择获取多列的值