def data_draw(csv_file): page = Page(csv_file + ":按区域分析") d = pd.read_csv(csv_file, engine='python', encoding='utf-8') # 读取CSV转为dataframe格式,并丢弃评论为空的的记录 position_info = d['positionName'].value_counts() position_bar = pyecharts.Bar('职位信息柱状图') position_bar.add('职位', position_info.index, position_info.values, is_stack=True, is_label_show=True) position_bar.render(csv_file[:-4] + "_职位信息柱状图.html") # 取CSV文件名的前8位数 page.add_chart(position_bar) salary_info = salary_count(csv_file) salary_bar = pyecharts.Bar('月薪柱状图') salary_bar.add('月薪', list(salary_info.keys()), list(salary_info.values()), is_stack=True, is_label_show=True) salary_bar.render(csv_file[:-4] + "_月薪柱状图.html") # 取CSV文件名的前8位数 page.add_chart(salary_bar) data = industryField_counts(csv_file) industryField_pie = pyecharts.Pie("", "行业领域饼图", title_pos="right", width=1200, height=600) industryField_pie.add("", list(data.keys()), list(data.values()), radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') industryField_pie.render(csv_file[:-4] + "_行业领域饼图.html") # 取CSV文件名的前8位数 page.add_chart(industryField_pie) companySize_info = d['companySize'].value_counts() companySize_pie = pyecharts.Pie("", "公司规模饼图", title_pos="right", width=1200, height=600) companySize_pie.add("", companySize_info._index, companySize_info.values, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') companySize_pie.render(csv_file[:-4] + "_公司规模饼图.html") # 取CSV文件名的前8位数 page.add_chart(companySize_pie) financeStage_info = d['financeStage'].value_counts() financeStage_pie = pyecharts.Pie("", "公司融资阶段饼图", title_pos="right", width=1200, height=600) financeStage_pie.add("", financeStage_info._index, financeStage_info.values, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') financeStage_pie.render(csv_file[:-4] + "_公司融资阶段饼图.html") # 取CSV文件名的前8位数 page.add_chart(financeStage_pie) workyear_info = d['workYear'].value_counts() workyear_pie = pyecharts.Pie("", "职位工作经验饼图", title_pos="right", width=1200, height=600) workyear_pie.add("", workyear_info._index, workyear_info.values, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') workyear_pie.render(csv_file[:-4] + "_职位工作经验饼图.html") # 取CSV文件名的前8位数 page.add_chart(workyear_pie) education_info = d['education'].value_counts() education_pie = pyecharts.Pie("", "职位学历要求饼图", title_pos="right", width=1200, height=600) education_pie.add("", education_info._index, education_info.values, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') education_pie.render(csv_file + "_职位学历要求饼图.html") # 取CSV文件名的前8位数 page.add_chart(education_pie) page.render(csv_file[:-4] + "_工作分析汇总.html")
def aboutMe(request): gauge = pyecharts.Gauge('', background_color='#f5f5f5') gauge.add('title', 'Percent', 80.66, scale_range=[0, 100], is_more_utils=True) gauge.show_config() result = gauge.render_embed() data = [("海门", 9), ("鄂尔多斯", 10), ("招远", 12), ("舟山", 18), ("齐齐哈尔", 10), ("盐城", 15)] geo = pyecharts.Geo("全国主要城市空气质量", "data from pm2.5", title_color="#000", title_pos="center", background_color='#f5f5f5') attr, value = geo.cast(data) geo.add("", attr, value, type="effectScatter", is_random=True, effect_scale=5, is_more_utils=True) geo.show_config() result1 = geo.render_embed() attr = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] v1 = [20, 33, 133, 124, 24, 313] v2 = [2.6, 12, 31, 241, 324, 134] bar = pyecharts.Bar('Bar Sample', background_color='#f5f5f5') bar.add("A", attr, v1, mark_line=["average"], mark_point=["min", "max"]) bar.add("B", attr, v2, mark_line=["average"], mark_point=["min", "max"], is_more_utils=True) bar_result = bar.render_embed() pie = pyecharts.Pie('', background_color="#f5f5f5") pie.add("", attr, v1, is_lable_show=True, lable_text_color="#156ACF", is_more_utils=True) pie.show_config() pie_result = pie.render_embed() liquid = pyecharts.Liquid('', background_color="#000") liquid.add("", [0.66, 0.5], ['diamond'], ['#294D99', '#156ACF'], is_more_utils=True) liquid.show_config() liquid_result = liquid.render_embed() return render_to_response( 'AboutMe.html', { 'result': result, 'result1': result1, 'bar_result': bar_result, 'pie_result': pie_result, 'liquid_result': liquid_result })
def click2(self): conn = pymysql.connect(host='localhost', user='******', password='******', port=3306, db='maoyan',charset='utf8mb4') sql = "select * from films" db = pd.read_sql(sql, conn) t1 = threading.Thread(target=self.myshow) year = int(self.comboBox.currentText()) month = int(self.comboBox_2.currentText()) t2 = threading.Thread(target=self.mytr,args = (year,month)) if month < 13: db_ = db[(db.year == year) & (db.month == month)] elif month > 123: db_= db[(db.year == year)&(db.month>0)&(db.month<4)] elif month == 456: db_ = db[(db.year == year) & (db.month > 3) & (db.month < 7)] elif month == 789: db_ = db[(db.year == year) & (db.month > 6) & (db.month < 10)] elif month == 101112: db_ = db[(db.year == year) & (db.month > 9) & (db.month < 13)] else: db_ = db x, y = visual(db_) pie = pyecharts.Pie() pie.add("", x, y, is_label_show=True, radius=[0, 50], center=[75, 50],legend_orient="vertical", legend_pos="right") bar = pyecharts.Bar("", title_pos="left") bar.add("", x, y, mark_line=["max", "average"], xaxis_interval=0,is_labal_show=True) grid = pyecharts.Grid(width=1200) grid.add(bar, grid_right='50%') grid.add(pie, grid_left="50%") grid.render(("db%d.html")%(year*100+month)) self.widget.load(QUrl('file:///db%d.html'%(year*100+month))) t1.start() t2.start()
def test_case_runhistory_report2(): REMOTE_HOST = "https://pyecharts.github.io/assets/js" bar = pyecharts.Pie() bar.add("Sports", ["Football", "Basketball", "Baseball", "Tennis", "Swimming"], [23, 34, 45, 56, 67], is_more_utils=True) log.log().logger.info(request) if request.method == 'GET': log.log().logger.info('post') info = request.values log.log().logger.info('info : %s' % info) id = viewutil.getInfoAttribute(info, 'id') log.log().logger.info('id: %s' % id) if len(test_case_manage.test_case_manage().show_test_cases(['id'], [id], [], 2)) == 1: return render_template("uitest/test_batch_result.html", id=id, type='test_case', test_suite_id='', myechart=bar.render_embed(), host=REMOTE_HOST, script_list=bar.get_js_dependencies()) else: return render_template("uitest/test_cases.html") else: return render_template("uitest/test_cases.html")
def test_batch_detail_report(): REMOTE_HOST = "https://pyecharts.github.io/assets/js" bar = pyecharts.Pie() bar.width = 700 bar.height = 400 log.log().logger.info(request) if request.method == 'GET': log.log().logger.info('post') info = request.values log.log().logger.info('info : %s' % info) id = viewutil.getInfoAttribute(info, 'test_suite_id') log.log().logger.info('id: %s' % id) statusList = test_batch_manage.test_batch_manage( ).show_test_batch_status(id) nameList, valueList = bar.cast(statusList) bar.add("results", ['失败', '待执行', '执行中', '成功'], valueList[0:4], is_more_utils=True, is_area_show=True, is_label_show=True, legend_pos="50%") return render_template("uitest/test_batch_detail_report.html", id=id, myechart=bar.render_embed(), host=REMOTE_HOST, script_list=bar.get_js_dependencies()) # return render_template("uitest/test_batch_report.html", id=id) else: return render_template('test_suite.html')
def create_Pie(): sun = 0 cloud = 0 lit_rain = 0 mit_rain = 0 sail = 0 shadom = 0 z_rain = 0 th_rain = 0 for i in types: if i == '晴': sun += 1 elif i == '多云': cloud += 1 elif i == '小雨': lit_rain += 1 elif i == '中雨': mit_rain += 1 elif i == '阴': shadom += 1 elif i == '阵雨': z_rain += 1 elif i == '雷阵雨': th_rain += 1 elif i == '扬沙': sail += 1 pie = pyecharts.Pie("全国天气类型比例", '2018-4-16') pie.add('', weather, [mit_rain, lit_rain, sail, sun, th_rain, cloud, shadom, z_rain], is_label_show=True, label_text_color=None, legend_orient='vertical', radius=[40, 50], center=[50, 50]) pie.add('', ['中雨', '小雨', '扬沙', '晴'], [lit_rain, mit_rain, sun, sail], radius=[10, 35], center=[50, 50], rosetype='area') pie.render('Pie-weather.html')
def visual_pie_pye(data, path): ''' use visual_pie_pye() to generate a html file ''' data = OrderedDict( sorted(data.items(), reverse=True, key=lambda x: x[1]['prop'])) labels = list(data.keys())[:10] + ['other'] sizes = [round(data[style]['prop'], 2) for style in labels[:-1]] othersize = 1 - sum(sizes) sizes.append(othersize) #x:labels y:sizes pie = pye.Pie("Proportions of Different Genres of Films", title_pos='center', width=1080, height=640) kwargs = dict( radius=(40, 75), label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left', is_toolbox_show=False, ) pie.add("", labels, sizes, **kwargs) pie.render(path)
def get_pie(): pie = pyecharts.Pie() style = pyecharts.Style() pie_style = style.add(label_pos="center", is_label_show=True, label_text_color=None) return pie, pie_style
def read_1688_all(cid, cat_name): page = pyecharts.Page() # 实例化page类 bar = read_1688_index(cid, cat_name) page.add(bar) attr_list = mongo_client2.get_1688attr(cid) # attrs = [] # for attr in attr_list: # attrs.append(attr) rows_by_type = defaultdict(list) for attr in attr_list: rows_by_type[attr['attr_type']].append(attr) for attr_type in rows_by_type.items(): # print(attr_type[1]['attr_value']) attr_value_index_group = [] attr_value_group = [] for attr in attr_type[1]: attr_value_index_group.append(attr['attr_value_index']) attr_value_group.append(attr['attr_value']) # print(attr_type[0]+"\t"+attr['attr_value']) # attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] # v1 = [11, 12, 13, 10, 10, 10] pie = pyecharts.Pie(attr_type[0], title_pos='50%') pie.add(attr_type[0], attr_value_group, attr_value_index_group, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left') page.add(pie) # print(rows_by_type) # pie # attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] # v1 = [11, 12, 13, 10, 10, 10] # pie = Pie("饼图-圆环图示例", title_pos='50%') # pie.add("", attr, v1, radius=[40, 75], label_text_color=None, # is_label_show=True, legend_orient='vertical', legend_pos='left') # TODO 配置Grid类 # grid = Grid(height=720, width=1200) # 初始化,参数可传page_title,width,height # grid.add(bar, grid_bottom="60%", grid_left="60%") # 添加要展示的图表,并设置显示位置 # # grid.add(line, grid_bottom="60%", grid_right="60%") # 添加要展示的图表,并设置显示位置 # grid.add(pie, grid_bottom="60%", grid_right="60%") # grid.add(scatter, grid_top="60%", grid_left="60%") # 添加要展示的图表,并设置显示位置 # grid.add(es, grid_top="60%", grid_right="60%") # 添加要展示的图表,并设置显示位置 # grid.render("Grid_并行显示多张图表.html") # return grid return page
def pie_chart(x, y, title=None): pie = pyecharts.Pie(width=700, height=450) pie.add(title, x, y, radius=[40, 75], is_label_show=True, legend_orient='vertical', legend_pos='left', label_text_color=None, label_text_size=15) return pie
def map_new_new(self, location, count, key): pie = pyecharts.Pie('{}职业分布'.format(key), width=1500, height=800, title_color='blue', title_pos='bottom') pie.add('{}'.format(key), location, count, is_random=True, is_label_show=True) pie.render(r'E:\github\bingtu\%s.html' % key)
def democ(data): es = pyecharts.Pie("") sum = 0 for i in data.values(): sum += 1 print(sum) flag = 1 for title in data.items(): if title[1] < 10: pass es.add('', data.keys().data.values()) flag += 1 es.render() es.render()
def gender_pie(title_name, gender_name, gender_num): total_num = 0 for i in gender_num: total_num += i subtitle_name = '共有%d个好友' % (total_num) pie = pyecharts.Pie(title=title_name, subtitle=subtitle_name) pie.add('', gender_name, gender_num, is_label_show=True) pie_file_name = './' + title_name + '.html' try: pie.render(path=pie_file_name) print('%s已保存至%s' % (title_name, pie_file_name)) except Exception as e: logging.debug(u'Error:%s' % e) pass
def sex_distribution(sexData): ''' 性别饼图 :return: null ''' number = [] number.append(sexData.count('0')) number.append(sexData.count('1')) number.append(sexData.count('2')) attr = ['未知', '男', '女'] pie = pyecharts.Pie("性别图") pie.add("", attr, number,is_label_show=True) return pie
def draw_district_pic(csv_file): page = Page(csv_file + ":城市区域职位分析") d = pd.read_csv(csv_file, engine='python', encoding='utf-8') # 读取CSV转为dataframe格式,并丢弃评论为空的的记录 district_info = d['district'].value_counts() geo1 = Geo("", "城市区域职位分布", title_pos="center", width=1200, height=600, background_color='#404a59', title_color="#fff") geo1.add("", district_info.index, district_info.values, maptype="广州", visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False, is_piecewise=True, visual_split_number=10, symbol_size=15, is_visualmap=True, is_more_utils=True) geo1.render(csv_file[:-4] + "_城市区域职位dotmap.html") page.add_chart(geo1) district_pie = pyecharts.Pie("", "区域职位饼图", title_pos="right", width=1200, height=600) district_pie.add("", district_info._index, district_info.values, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') district_pie.render(csv_file[:-4] + "_区域职位饼图.html") # 取CSV文件名的前8位数 page.add_chart(district_pie) page.render(csv_file + "_城市区域分析汇总.html")
def amount(self): head_list = [] count_list = [] for collection_name in self.collections: count = 0 for item in self.db[collection_name].find(): if 'commodity_name' not in item.keys(): continue count += 1 if count != 0: head_list.append(collection_name) count_list.append(count) pie = pyecharts.Pie('京东口红') pie.add('数量', head_list, count_list, is_label_show=True) pie.render('visualization/amount.html')
def color_distribution(self): color_type_dict = {} for collection_name in self.collections: for item in self.db[collection_name].find(): if 'color_type' not in item.keys(): continue color_type = item['color_type'] if color_type == '其它': continue if color_type in color_type_dict.keys(): color_type_dict[color_type] += 1 else: color_type_dict[color_type] = 1 pie = pyecharts.Pie() pie.add('色系分布', list(color_type_dict.keys()), list(color_type_dict.values()), is_label_show=True) pie.render('visualization/color_distribution.html')
def mfRatio(self, chatroom=None): # 男女比例 male = female = othor = 0 lables = ['男', '女', '其他'] path = self.savedir + 'mfRatio.html' if chatroom: cmd = 'mfRatio %s' % chatroom myLogging(self.cmdFile, self.nickName, infoType='cmd', other=cmd) try: chatroom == self.instance.search_chatrooms( name=chatroom)[0]['NickName'] except Exception as reason: self.instance.send('在您的通讯录中没有找到该群[%s]' % chatroom) myLogging(self.errFile, self.nickName, infoType='err', other=cmd, info=reason) return memberList = self.getChatroomMembers(chatroom)['MemberList'] subtitle = self.nickName + ':' + chatroom else: cmd = 'mfRatio' myLogging(self.cmdFile, self.nickName, infoType='cmd', other=cmd) memberList = self.frdInfoList[1:] subtitle = self.nickName male = len([1 for each in memberList if each['Sex'] == 1]) female = len([2 for each in memberList if each['Sex'] == 2]) other = len([0 for each in memberList if each['Sex'] == 0]) values = [male, female, other] pie = pyecharts.Pie('微信好友男女比例', subtitle) pie.add('男女比例', lables, values, is_label_show=True) pie.render(path) self.instance.send('@fil@%s' % path) os.remove(path) myLogging(self.cmdFile, self.nickName, infoType='cmd', status='success', other=cmd)
def t10(pa): pie = p.Pie("新兴与传统职业学历经验需求对比", width=700, height=400) pie.add("传统学历需求", next(pa), next(pa), radius=[50, 55], center=[35, 53]) pie.add("新兴学历需求", next(pa), next(pa), radius=[0, 45], center=[35, 53], rosetype='radius', is_random=True) pie.add("传统经验需求", next(pa), next(pa), radius=[50, 55], center=[70, 53]) pie.add("新兴经验需求", next(pa), next(pa), radius=[0, 45], center=[70, 53], rosetype='radius', legend_orient='vertical', legend_pos='left', legend_top='center', is_random=True, is_toolbox_show=False) return pie
def friends_sex(): sex = [] with open('wechatfriends.txt', mode='r', encoding='utf-8') as f: rows = f.readlines() for i in rows: # if (i.split(',')[2]) == '': # pass # print(i.split(',')) sex.append(i.split(',')[2]) labels = ['汉子', 'lady', '性别不明'] value = [sex.count('1'), sex.count('2'), sex.count('0')] pie = pyecharts.Pie('好友性别比例', '好友总人数:%d' % len(sex), title_pos='center') pie.add( '', labels, value, radius=[30, 75], is_label_show=True, legend_orient="vertical", legend_pos="left", ) pie.render('微信好友性别比例.html')
cat_sum[i['name']] = 0 for i in range(l): cated = False for j in dic: flg = False for k in j['keys']: if accounts['CHECKING SUMMARY']['description'][i].lower().find( k) != -1: cat_sum[j['name']] += accounts['CHECKING SUMMARY']['amount'][i] flg = True cated = True break if flg is True: break if cated is False: print(accounts['CHECKING SUMMARY']['description'][i]) cat_sum['other'] += accounts['CHECKING SUMMARY']['amount'][i] cat_sum # In[81]: pie = pyecharts.Pie() attr = [] v = [] for i in cat_sum: attr.append(i) v.append(round(cat_sum[i] * -1, 2)) pie.add('test', attr, v, is_legend_show=False, is_label_show=True) # In[ ]:
attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%", ) attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = echarts.Pie("饼图示例", title_pos="55%") pie.add( "", attr, v1, radius=[45, 65], center=[65, 50], legend_pos="80%", legend_orient="vertical", ) grid = echarts.Grid(width=1200) grid.add(line, grid_right="55%") grid.add(pie, grid_left="60%") grid.render(path='tmp/grid.html')
#研究'年龄层次匹配','城市层级','消费档次','性别'四个字段的用户画像 #获取数据 a = ['年龄层次匹配', '城市层级', '消费档次', '性别'] attr = [] y = [] for i in a: attri = df[i].value_counts().index.tolist() yi = df[i].value_counts().values.tolist() attr.append(attri) y.append(yi) #在一个页面显示4张饼图 pie = pe.Pie('某平台用户年龄层次、城市层级、消费档次、性别画像研究环形图', title_pos='center', height=600, width=1000) pie.add('年龄层次', attr[0], y[0], radius=[25, 35], center=[30, 30], is_legend_show=False, is_label_show=True) pie.add('城市层级', attr[1], y[1], radius=[25, 35], center=[75, 30], is_legend_show=False, is_label_show=True)
def find(name): user = "******" password = "******" db = pymysql.connect(host="localhost", user=user, password=password, charset="utf8") cursor = db.cursor() cursor.execute('USE `ujn_a`;') names = name + 's' cursor.execute('DROP VIEW IF EXISTS {};'.format(names)) sql_1 = 'CREATE VIEW {} AS SELECT qcwy.xexperience,qcwy.education FROM qcwy WHERE title like "%{}%" '.format( names, name) cursor.execute(sql_1) cursor.execute("select count(*) from " + names) alls = cursor.fetchone()[0] list1 = ['本科', '硕士', '博士'] list_edu = [] list_edu_sql = [ "select count(*) from {} where education = '{}';".format(names, i) for i in list1 ] for i in list_edu_sql: cursor.execute(i) list_edu.append(cursor.fetchone()[0]) list2 = ['无工作经验', '1年经验', '2年经验', '3-4年经验', '5-7年经验', '8-9年经验', '10年以上经验'] list_exp = [] list_exp_sql = [ "select count(*) from {} where xexperience = '{}';".format(names, i) for i in list2 ] for i in list_exp_sql: cursor.execute(i) list_exp.append(cursor.fetchone()[0]) p.configure(global_theme='macarons') # 设置主题 bing = p.Pie() attr = list2 v1 = list_exp bing.add("", attr, v1, is_label_show=True, is_toolbox_show=False, legend_top='bottom') bing.render('static/html/bing.html') list4 = [] for i in range(3): qiu = p.Liquid(title=list1[i], title_pos='center', title_text_size=30, title_top='80%', width=600, height=400) list3 = [round(list_edu[i] / alls, 2)] list4.extend(list3) qiu.add(list1[i], list3, is_liquid_animation=True, is_toolbox_show=False, liquid_color=['#21bbff', '#00b6ff', '#23c4ff', '#47c7ff'], is_liquid_outline_show=False) qiu.render('static/html/qiu{}.html'.format(i + 1)) # 返回 n = 1 e_all = 0 for i in list_exp[1:]: e_all = e_all + i / alls / 21 * n n = n + 1 n = 1 d_all = 0 for i in list_edu[1:]: d_all = d_all + i / alls / 2 * n n = n + 1 if e_all > d_all: if e_all - d_all <= 0.06: result = '考研和直接就业都很不错呢' else: result = '建议您毕业后直接就业哦' else: result = '建议您准备考研哦' if name == '学习': name = '机器学习' back = [name, result] return back return
def data_draw(csv_file): page = Page(csv_file + ":按区域分析") #读取csv转为dataframe格式 d = pd.read_csv(csv_file, engine='python', encoding='utf-8') position_info = d['positionname'].value_counts() #画职位信息柱状图 position_bar = pyecharts.Bar('职位信息柱状图') position_bar.add('职位', position_info.index, position_info.values, is_stack=True, is_label_show=True) position_bar.render(csv_file[:-4] + "_职位信息柱状图.html") page.add_chart(position_bar) salary_info = d['salary'].values #画薪水信息柱状图 salary_bar = pyecharts.Bar('薪水信息柱状图') dict = { '2k-': 0, '2k-5k': 0, '5k-10k': 0, '10k-15k': 0, '15k-20k': 0, '20k-30k': 0, '30k+': 0 } for salary in salary_info: #正则表达式:^开始符,$结束符,[]:范围,\d:数字,{}位数 if re.match('^[0-1]k-*|.*-[0-1]k$', salary) != None: dict['2k-'] += 1 if re.match('^[2-4]k-*|.*-[2-4]k$', salary) != None: dict['2k-5k'] += 1 if re.match('^[5-9]k-*|.*-[5-9]k$', salary) != None: dict['5k-10k'] += 1 if re.match('^1[0-4]k-*|.*-1[0-4]k$', salary) != None: dict['10k-15k'] += 1 if re.match('^1[5-9]k-*|.*-1[5-9]k$', salary) != None: dict['15k-20k'] += 1 if re.match('^2[0-9]k-*|.*-2[0-9]k$', salary) != None: dict['20k-30k'] += 1 if re.match('^[3-9][0-9]k-*|.*-[3-9][0-9]k$|\d{3,}k-*|.*-\d{3,}k$', salary) != None: dict['30k+'] += 1 salary_bar.add('薪水', list(dict.keys()), list(dict.values()), is_stack=True, is_label_show=True) salary_bar.render(csv_file[:-4] + '_薪水信息柱状图.html') page.add_chart(salary_bar) industryfield_info = d['industryfield'].values #行业分布饼状图 industryfield_pie = pyecharts.Pie('行业分布饼状图', title_pos='right') industryfields = [] for i in range(len(industryfield_info)): try: data = re.split('[,、 ]', industryfield_info[i]) #逗号,顿号,空格 except: continue for j in range(len(data)): industryfields.append(data[j]) counts = Counter(industryfields) #字典类型 print(type(counts)) industryfield_pie.add('', list(counts.keys()), list(counts.values()), radius=[15, 60], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') industryfield_pie.render(csv_file[:-4] + '_行业分布饼状图.html') page.add_chart(industryfield_pie) companysize_info = d['companysize'].value_counts() #公司规模饼状图 companysize_pie = pyecharts.Pie('公司规模饼状图', title_pos='right') companysize_pie.add('', companysize_info.index, companysize_info.values, radius=[15, 60], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') companysize_pie.render(csv_file[:-4] + '_公司规模饼状图.html') page.add_chart(companysize_pie) #公司融资情况饼状图 financestage_info = d['financestage'].value_counts() financestage_pie = pyecharts.Pie('公司融资信息饼状图', title_pos='right') financestage_pie.add('', financestage_info.index, financestage_info.values, radius=[15, 60], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') financestage_pie.render(csv_file[:-4] + '_公司融资信息饼状图.html') page.add_chart(financestage_pie) #工作经验饼状图 workyear_info = d['workyear'].value_counts() workyear_pie = pyecharts.Pie('工作经验信息饼状图', title_pos='right') workyear_pie.add('', workyear_info.index, workyear_info.values, radius=[15, 60], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') workyear_pie.render(csv_file[:-4] + '_工作经验信息饼状图.html') page.add_chart(workyear_pie) #学历要去饼状图 education_info = d['education'].value_counts() education_pie = pyecharts.Pie('学历要求信息饼状图', title_pos='right') education_pie.add('', education_info.index, education_info.values, radius=[15, 60], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') education_pie.render(csv_file[:-4] + '_学历要求信息饼状图.html') page.add_chart(education_pie) #工作地点饼状图 district_info = d['district'].value_counts() district_pie = pyecharts.Pie('工作地点信息饼状图', title_pos='right') district_pie.add('', district_info.index, district_info.values, radius=[15, 60], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') district_pie.render(csv_file[:-4] + '_工作地点信息饼状图.html') page.add_chart(district_pie) #汇总 page.render(csv_file[:-4] + '.html')
def view(): """ 价格柱状图 """ # Excel存储路径 excel_path = os.path.dirname( os.path.realpath(__file__)) + '\\utils\\pdd.xlsx' # 激活表格 wb = xlrd.open_workbook(filename=excel_path) # sheet sheet_name = wb.sheet_names()[0] # sheet 内容 sheet_content = wb.sheet_by_name(sheet_name) # 获取第五列所有价格 cols_price = sheet_content.col_values(4)[1:] # 统计各价格区间的商品总量 price_zone = { 'less_than_1000': 0, # 非正常价格 'less_than_2000': 0, # 1000-2000 'less_than_3000': 0, # 2000-3000 'less_than_4000': 0, # 3000-4000 'greater_than_4000': 0, # 大于4000 } for price in cols_price: pirce_ = int(price) if pirce_ > 4000: price_zone['greater_than_4000'] += 1 elif pirce_ > 3000 and pirce_ <= 4000: price_zone['less_than_4000'] += 1 elif pirce_ > 2000 and pirce_ <= 3000: price_zone['less_than_3000'] += 1 elif pirce_ > 1000 and pirce_ <= 2000: price_zone['less_than_2000'] += 1 else: price_zone['less_than_1000'] += 1 data = [] labels = [] for k, v in price_zone.items(): data.append(v) labels.append(k) bar = pyecharts.Bar("各价格区间的商品数量", 'https://github.com/Northxw/') bar.add('', labels, data, bar_category_gap="30%") bar.render(path=os.path.dirname(os.path.realpath(__file__)) + '\\view\\price.html') # 获取第六列标签数据 cols_tags = sheet_content.col_values(6)[1:] tags = { '顺丰包邮': 0, '极速退款': 0, '退货包运费': 0, '品牌馆': 0, '全国联保': 0, } for tag in cols_tags: if '顺丰包邮' in tag: tags['顺丰包邮'] += 1 elif '极速退款' in tag: tags['极速退款'] += 1 elif '退货包运费' in tag: tags['退货包运费'] += 1 elif '品牌馆' in tag: tags['品牌馆'] += 1 elif '全国联保' in tag: tags['全国联保'] += 1 data = [] labels = [] for k, v in tags.items(): data.append(v) labels.append(k) pie = pyecharts.Pie("商家标签", 'https://github.com/Northxw/') pie.add('', labels, data, is_label_show=True) pie.render(path=os.path.dirname(os.path.realpath(__file__)) + '\\view\\tags.html')
sports[s] = sports.get(s, 0) + 1 ts = u.teams.split() for t in ts: teams[t] = teams.get(t, 0) + 1 print(sports) print(teams) # In[36]: from collections import Counter, OrderedDict teams_most = OrderedDict(Counter(teams).most_common(40)) teams_most['其他'] = sum(teams.values()) - sum(teams_most.values()) print(teams_most) pie = ec.Pie(width=1000) pie.add('队伍', teams_most.keys(), teams_most.values(), is_legend_show=False, is_label_show=True) pie # In[37]: s = sorted(sports.items(), key=lambda x: x[1], reverse=True) s = OrderedDict(s) pie = ec.Pie(width=1000) pie.add('运动', s.keys(), s.values(), is_legend_show=False, is_label_show=True) pie # In[ ]:
# with open('../../data/top10.txt') as f: # row = f.readlines() # arr = [ss.strip('\n') for ss in row] # for l in arr: # txt = wordlist(l) # wordWeight = tfidf(txt) # s = sorted(wordWeight,key=lambda x:x[1],reverse=True)[:3] # ll.append(s) # print(ll) ll = [[['stuff', 0.44233918732073285]], [['network', 0.30221302424344187]], [['boys', 0.43515469193302975]], [['universe', 0.48004267235639847]], [['world', 0.26678657924332194]], [['right', 0.35641846295458396]], [['information', 0.27579849586805472]], [['people', 0.43308190878605118]], [['brain', 0.34786262139146906]], [['cancer', 0.52024972856630003]]] pie = pyecharts.Pie('top10文章中的关键词') x = [] y = [] for s in ll: for l in s: print(s) x.append(l[0]) y.append(l[1]) pie.add('', x, y, is_random=True, legend_pos='right', legend_orient='vertical', radius=[20, 75], rosetype='radius')
house = house.drop('house_info',axis=1) #删除House_info这一列 house.loc[house['location'].isna(),'location'] = house.loc[house['location'].isna()].house.apply(lambda x : x.split()[1]) #location公寓的有缺失位置进行处理 #可视化分析 #房屋户型分布数量前十柱形图 z = house.apartment.value_counts()[:10].sort_values() bar = pyecharts.Bar("房屋户型分布前十","南京·NanJing") bar.add(z,z.index,y_axis = list(z.values),is_convert= True,is_label_show =True,label_pos = 'inside',label_color = ["#996666"]) bar.render("南京租房房屋户型分析.html") #各行政区房屋租赁数量分布及占比 part = house.part.value_counts().sort_values() part_bar = pyecharts.Bar("各行政区房屋租赁数量分布及占比","南京·NanJing") part_bar.add(part,part.index,part.values,is_label_show = True,label_color = ['#999999'],is_convert = True,label_pos = "inside") pie_part = pyecharts.Pie(title_pos = "40%") pie_part.add(part,part.index,part.values,is_label_show = True,legend_pos = '90%',legend_orient="vertical",center = [65,50]) grid = pyecharts.Grid(page_title="各行政区房屋租赁数量分布及占比",width=1200) grid.add(part_bar,grid_right = "60%") grid.add(pie_part,grid_left = "50%") grid.render("南京租房数量分析.html") #了解一下不同地区租房平均情况 single_price = round(house.loc[house.house_type == 'single'].money.groupby(house.loc[house.house_type == 'single']['part']).mean(),0) all_price = round(house.loc[house.house_type == 'all'].money.groupby(house.loc[house.house_type == 'all']['part']).mean(),0) line = pyecharts.Line("各行政区租房价格·¥","南京·NanJing") line.add("整租",all_price.index,all_price.values,is_label_show = True) line.add("合租",single_price.index,single_price.values,is_label_show = True) line.render("南京租房房价分析.html")
'''******用户平台年龄以年为单位,用.dt.days获取了天数后除以365''' df['用户平台年龄'] = df['用户平台年龄'].dt.days / 365 '''******用行为时间字段得出行为时刻''' df['行为时刻'] = df['行为时间'].dt.hour ''' 获取需要用到的necklace的数据data ''' data = df[df['产品类别'] == 'Necklace'] ''' 第二步指标的量化及初判 ''' ''' 行为类别 ''' '''全样本的行为类别''' pie = pe.Pie('全样本的行为类别环形图', title_pos='center', height=500, width=600) attr = df['行为类别'].value_counts().index.tolist() d = df['行为类别'].value_counts().values.tolist() pie.add('全样本的行为类别环形图', attr, d, is_more_utils=True, is_label_show=True, is_legend_show=False, radius=[40, 75]) pie.render('全样本的行为类别环形图.html') order_all = df['行为类别'].value_counts()['Order'] / len(df['行为类别']) print('最终实现了购买行为占所有关注用户的行为的%.2f%%' % (order_all * 100)) #所有有购买行为的用户(去重)/所有用户 order_cust_all = len(df[df['行为类别'] == 'Order']['客户编码'].value_counts()) / len( df['客户编码'].value_counts())