题目

小王要对这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("[、,。:“”;?\n]","",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])     ③   #支持中文显示 (1) 为实现上述功能①处代码为                             A . random.sample(wz,1) B . random.shuffle(wz) C . random.randint(1,10) (2) 请将②③处代码补充完整 ②③ 答案: A 【1】word[t]=1【2】plt. show()
信息技术 试题推荐
最近更新