for i in data['公司'].values: if i not in qiyetongjidata.keys(): qiyetongjidata[i]=1 else: qiyetongjidata[i]+=1 sort_qiyetongjidata=sorted(qiyetongjidata.items(),key=lambda x:x[1],reverse=True) labels=[] values=[] for i in sort_qiyetongjidata[:10]: labels.append(i[0]) values.append(i[1]) fig, ax = plt.subplots(figsize=(8, 4)) bar_height = 0.5 y = range(len(labels)) ax.barh(y, values, height=bar_height, color='#66b3ff') ax.set_yticks(y) ax.set_yticklabels(labels) ax.set_ylabel('企业') ax.set_xlabel('数量') ax.set_title('公司招聘岗位数量统计横向柱状图') plt.subplots_adjust(left=0.3,bottom=0.15)
时间: 2023-06-05 16:06:47 浏览: 78
黑') ax.set_yticks(y) ax.set_yticklabels(labels) ax.set_xlabel('数量') ax.invert_yaxis() plt.show()
这段代码的功能是什么?
这段代码的功能是通过统计数据中不同公司出现的次数,并将结果按照出现次数由高到低排序,最终绘制出前十个出现次数最多的公司并展示在水平柱状图上。
相关问题
qiyetongjidata={} for i in data['公司'].values: if i not in qiyetongjidata.keys(): qiyetongjidata[i]=1 else: qiyetongjidata[i]+=1 sort_qiyetongjidata=sorted(qiyetongjidata.items(),key=lambda x:x[1],reverse=True) labels=[] values=[] for i in sort_qiyetongjidata[:10]: labels.append(i[0]) values.append(i[1]) fig, ax = plt.subplots(figsize=(8, 4)) bar_height = 0.5 y = range(len(labels)) ax.barh(y, values, height=bar_height, color='#66b3ff') ax.set_yticks(y) ax.set_yticklabels(labels) ax.set_ylabel('企业') ax.set_xlabel('数量') ax.set_title('公司招聘岗位数量统计横向柱状图') plt.subplots_adjust(left=0.3,bottom=0.15) plt.show()
这段代码的作用是对数据集中的公司名进行去重,并统计每个公司的出现次数,最后按照出现次数从大到小排序选择前10个公司,将它们的公司名和出现次数分别存入labels和values列表中,在图表上以横向条形图的形式展示。
cipintongji={} pattern = '|'.join(map(re.escape, separators)) for i in data['公司领域'].values: words = re.split(pattern, i) for i in words: word=i.strip() if word not in cipintongji.keys(): cipintongji[word]=1 else: cipintongji[word]+=1 wc = WordCloud(font_path='msyh.ttc', # 字体 background_color="white", # 颜色 max_words=50, # 词云显示的最大词数 width=1200, # 宽度 height=800, # 高度 # mask=back_coloring, # 背景图片 ) wc.generate_from_frequencies(cipintongji) # 显示图 plt.figure() plt.imshow(wc) plt.axis("off") plt.show()
这段代码的作用是将数据中的多个关键词进行切分,统计出各个关键词出现的频率,并且生成词云图。具体实现方式是:将数据中的分隔符用 | 连接成字符串 pattern,然后通过 re 模块的 split() 函数将字符串切分成多个单词,再循环遍历每个单词进行处理。将单词去除空格后,判断它是否出现在字典 cipintongji 的键中,如果出现则将对应的值加1,否则在字典中新建一个键值对,并将值初始化为1。最后通过 WordCloud 类生成词云图,指定字体路径等参数。