组卷题库 > 高中信息技术试卷库
试题详情
小王要对这10篇作文随机抽取1篇进行分词处理,并进行频率统计,在统计频率时需要去除单个的文字,请回答下列各题。文章收集后存放目录如图a所示,生成的词云如图b所示。

   

import import import

pandas as pd

os,jieba,re,random,wordcloud

matplotlib.pyplot as plt

from PIL import Image

wzdir = "./2021 浙江高考满分作文/"

wz = os.listdir(wzdir) #获得文件夹中所有文件的名称列表

wzrd =   ①      

f=open(wzdir+wzrd[0],encoding="utf-8")

dd=f.read ()

f.close()

#使用正则表达式去除文章中的标点符号

ss = re.sub("[、,。:“”;? ]","",dd)

wb = jieba.lcut(ss,cut_all=True)

word = {}

for i in wb:

  t =i.strip()

  if len(t)>1:

    if t in word:

      word[t]+=1

    else:

           ②    

      wc = wordcloud.WordCloud(font_path="msyh.ttc", width=800, height=600) wc.background_color="white"

      wc.fit_words (word)

      img = wc.to_array()

      plt.rcParams['font.sans-serif']=['SimHei'] plt.figure()

      plt.imshow(img)

      plt.axis(False)

      plt.title(wzrd[0].split(".")[0])

    ③  

#支持中文显示

知识点
参考答案
采纳过本试题的试卷
    教育网站链接