给我一个python 根据xlsx生成词云的代码
时间: 2023-04-06 18:01:07 浏览: 159
以下是一个基于Python和xlsxwriter库的生成词云的代码示例:
```python
import xlsxwriter
from wordcloud import WordCloud
# 读取Excel文件
workbook = xlsxwriter.Workbook('data.xlsx')
worksheet = workbook.add_worksheet()
# 写入数据
worksheet.write('A1', 'Python')
worksheet.write('A2', 'Java')
worksheet.write('A3', 'C++')
worksheet.write('A4', 'JavaScript')
worksheet.write('A5', 'PHP')
worksheet.write('A6', 'Ruby')
worksheet.write('A7', 'Swift')
worksheet.write('A8', 'Go')
worksheet.write('A9', 'Kotlin')
worksheet.write('A10', 'Rust')
# 生成词云
text = ' '.join(worksheet.col_values(0))
wordcloud = WordCloud(width=800, height=800, background_color='white').generate(text)
wordcloud.to_file('wordcloud.png')
# 关闭Excel文件
workbook.close()
```
这段代码可以生成一个包含Excel文件中所有单元格数据的词云图像,并将其保存为PNG文件。
阅读全文