根据上述数据集 词云展示“计算机视觉和模式识别”类别下的题目词云图 运用jupyter实现 词云图结果直接输出
时间: 2024-03-10 12:51:19 浏览: 93
好的,实现这个任务需要以下步骤:
1. 使用Python中的pandas库读取JSON格式的数据集,筛选出分类号为"cs.CV"的论文,并提取出它们的题目信息。
2. 使用Python中的jieba库对题目信息进行分词处理,去除停用词和单个字的词汇。
3. 使用Python中的wordcloud库生成词云图。
4. 在jupyter notebook中展示生成的词云图。
下面是Python代码实现:
```python
# 导入需要使用的库
import pandas as pd
import jieba
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 读取数据集
data = pd.read_json('arxiv-metadata-oai-2019.json', lines=True)
# 筛选出分类号为"cs.CV"的论文
cv_data = data[data['categories'].str.contains('cs.CV')]
# 提取出题目信息
titles = cv_data['title'].tolist()
# 对题目信息进行分词处理
stopwords = set(open('stopwords.txt', 'r', encoding='utf-8').read().splitlines()) # 导入停用词
words = []
for title in titles:
seg_list = jieba.cut(title)
for word in seg_list:
if len(word) > 1 and word not in stopwords:
words.append(word)
# 生成词云图
wordcloud = WordCloud(
font_path='msyh.ttc', # 设置字体
background_color='white', # 设置背景色
max_words=200, # 设置最大显示的词数
max_font_size=100 # 设置字体最大值
).generate(' '.join(words))
# 输出词云图
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
```
上述代码中,我们使用了一个停用词列表,将一些无意义的常用词汇过滤掉,这样可以使得词云图更加直观和具有代表性。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)