def get_salary(self, df): money = df["薪资"].apply(lambda x: np.array( x.replace("k", "").replace("K", "").split("-")).tolist()) money = money.apply(lambda x: (int(x[0]) + int(x[1])) / 2) # 重新分类薪资区间范围 df["薪资"] = pd.cut( money, bins=[0, 10, 20, 25, 30, 100], right=False, labels=np.array(["0-10k", "10k-20k", "20k-25k", "25k-30k", "30K+"])) data = df["薪资"].value_counts() funnel = Funnel("工程师薪资分布图", title_pos="center") funnel.add( name="薪资分布", attr=data.index, value=data.values, is_label_show=True, label_formatter='{b} {d}%', label_pos='inside', legend_orient='vertical', legend_pos='right', ) funnel.render(self.html_path + "salary.html") draw_pie(self.html_path + "salaryPie.html", "薪资分布", data.index, data.values)
def funnel_charts(): page = Page() chart_init = { "width": WIDTH, "height": HEIGHT, } attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] chart = Funnel("漏斗图示例", **chart_init) chart.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") page.add(chart) chart = Funnel("漏斗图示例", title_pos='center', **chart_init) chart.add("商品", attr, value, is_label_show=True, label_pos="outside", legend_orient='vertical', legend_pos='left') page.add(chart) return page
def funnel_orientataion(self): orientation = pd.read_csv(self.all_house_path, encoding='utf-8') orientation = orientation.groupby(by='orientation').count() orientation = orientation['price'].sort_values(ascending=False) attr = orientation.index value = orientation.values index = [] values = [] for i in attr: index.append(i) for i in value: values.append(i) # print(len(index), len(value)) funnel_orien = Funnel("房源朝向漏斗图", width=800, height=700, title_pos="center") funnel_orien.add( "朝向", attr, value, is_label_show=True, label_pos="outside", legend_pos="left", label_text_color="#000", legend_orient="vertical", funnel_gap=5, ) funnel_orien.render(path="funnel-orientataion.html")
def test_funnel(): # funnel_0 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] funnel = Funnel("漏斗图示例") funnel.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") funnel.render() # funnel_1 funnel = Funnel("漏斗图示例", width=600, height=400, title_pos='center') funnel.add("商品", attr, value, is_label_show=True, label_pos="outside", legend_orient='vertical', legend_pos='left') funnel.show_config() funnel.render()
def dan_wang(self): """ 获取淡旺季电影 :return: """ pro = self.get_pro() month_l = [] amount_l = [] for month in self.month_list: df = pro.bo_monthly(date=month) month_amount = df['month_amount'].sum() mon = f"{month[4:6]}月份" month_l.append(mon) amount_l.append(month_amount) funnel = Funnel("") funnel.add( "商品", month_l, amount_l, is_label_show=True, label_pos="inside", label_text_color="#fff", ) funnel.render(path="淡旺季.html", )
def create_charts(): page = Page() style = Style(width=WIDTH, height=HEIGHT) attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] chart = Funnel("漏斗图示例", **style.init_style) chart.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") page.add(chart) chart = Funnel("漏斗图示例", title_pos='center', **style.init_style) chart.add("商品", attr, value, is_label_show=True, label_pos="outside", legend_orient='vertical', legend_pos='left') page.add(chart) return page
def loudoutu(): '''漏斗图''' attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] funnel = Funnel("漏斗图示例") funnel.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") funnel.render('./info/漏斗图.html')
def test_funnel_labelpos_inside(): funnel = Funnel("漏斗图示例") funnel.add("商品", CLOTHES, prices, is_label_show=True, label_pos="inside", label_text_color="#fff") funnel.render()
def drawFunnel(title, data, savepath='./results'): if not os.path.exists(savepath): os.mkdir(savepath) funnel = Funnel(title, title_pos='center') funnel.use_theme('chalk') attrs = [i for i, j in data.items()] values = [j for i, j in data.items()] funnel.add("", attrs, values, is_label_show=True, label_pos="inside", label_text_color="#fff", legend_pos="left", legend_orient="vertical") funnel.render(os.path.join(savepath, '%s.html' % title))
def funnel_html(title, key, val): funnel = Funnel(title, title_pos="center", width="100%", height=300) funnel.add("", key, val, is_label_show=True, label_pos="outside", legend_orient="vertical", legend_pos="left") return funnel.render_embed()
def test_funnel_other_style(): funnel = Funnel("漏斗图示例", title_pos='center') funnel.add("商品", CLOTHES, prices, is_label_show=True, label_pos="outside", legend_orient='vertical', legend_pos='left') funnel.render()
def draw_edu_funnel(data): funnel = Funnel("妹子学历分布漏斗图") funnel.add("学历", edu_interval, data, is_label_show=True, label_pos="inside", label_text_color="#fff", title_top=50) return funnel
def draw_funnel(): attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] funnel = Funnel("漏斗图示例") funnel.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") funnel.render()
def draw_edu_funnel(data): funnel = Funnel("妹子学历分布漏斗图", title_top='center') funnel.add("学历", edu_interval, data, is_label_show=True, label_pos="inside", label_text_color="#fff", is_random=True) funnel.render() return funnel
def test_funnel_labelpos_inside(): funnel = Funnel("漏斗图示例") funnel.add( "商品", CLOTHES, prices, is_label_show=True, label_pos="inside", label_text_color="#fff", ) funnel.render()
def funnel(): from pyecharts import Funnel attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] funnel = Funnel("漏斗图示例") funnel.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") return template(funnel)
def test_funnel_other_style(): funnel = Funnel("漏斗图示例", title_pos="center") funnel.add( "商品", CLOTHES, prices, is_label_show=True, label_pos="outside", legend_orient="vertical", legend_pos="left", ) funnel.render()
def funnel_generate(event_names, value): # process -> list 用户选择的漏斗过程 ; values -> list impala返回的结果 # attr = ["过程1", "过程2", "过3", "过程4"] attr = event_names # value = [80, 60, 40, 20] value = value funnel = Funnel("漏斗图") funnel.add( " ", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff", ) return funnel
def ReadOther(): attr = ["城市社区服务", "环保项目", "帮扶活动", "文体活动", "安全医疗", "法律宣传讲座培训", "其他"] value = [373257, 159648, 212721, 246070, 143465, 120205, 93256] funnel = Funnel("项目类别统计", width='100%', height='100%', title_pos='center', title_text_size=16, title_color='#3B5077') funnel.add("类别统计", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff", label_text_size=8, legend_orient="vertical", legend_pos="left", legend_text_size=10) name = [] value = [] with open('data/全国院校统计前100.csv', 'r', encoding='utf-8') as file: reader = csv.reader(file) for row in reader: name.append(row[2]) value.append(row[1]) wordcloud = WordCloud(width='120%', height='100%') wordcloud.add("", name, value, word_size_range=[8, 30]) schema = [ ("博士研究生", 1000000), ("硕士研究生", 1000000), ("大学本科", 1000000), ("大学专科", 1000000), ("中等专科", 1000000), ("技工学校", 1000000), ("高中", 1000000), ("初中", 1000000), ("职业高中", 1000000), ("小学", 1000000), ] v1 = [[9979, 48300, 716519, 448358, 118656, 36065, 600168, 697599, 54160, 270191]] v2 = [[863336, 462984, 953627, 646927, 234893, 170111, 354992, 241914, 158316, 84504]] radar = Radar(width='100%', height='110%') radar.config(schema) radar.add("实际人数分布", v1, is_splitline=True, is_axisline_show=True, label_text_size=8, legend_orient="vertical") radar.add("人数比例分布", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single', legend_pos="right", legend_text_size=10, legend_orient="vertical") attr = ["群众", "中国少年先锋队队员", "无党派民主人士", "台湾民主自治同盟盟员", "九三学社社员", "中国致公党党员", "中国农工民主党党员", "中国民主促进会会员", "中国民主建国会会员", "中国民主同盟盟员", "中国国民党革命委员会会员", "中国共产主义青年团团员", "中国共产党预备党员", "中国共产党党员"] v2 = [34688546, 2725751, 95275, 2180, 713840, 3787, 30049, 7356, 7278, 14952, 21065, 12621879, 294148, 6089445] pie = Pie(width='100%', height='90%', title_pos='center', title_text_size=10) pie.add("政治面貌统计", attr, v2, center=[50, 50], is_random=True, radius=[10, 80], rosetype="area", is_legend_show=True, is_label_show=False, legend_pos="left", legend_text_size=10, legend_orient="vertical") attr = ['2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018'] line = Line(width='100%', height='100%') line.add("志愿者数增长", attr, [1, 59580, 532707, 258196, 26194, 628465, 311171, 1970707, 1539836, 2807952, 6566130, 6775399, 36504414, 7408478], mark_line=["average"]) line.add("团体增长", attr, [371, 485, 471, 924, 798, 1266, 2887, 4963, 4848, 7781, 24203, 15936, 25280, 5376], mark_line=["average"]) line.add("项目增长", attr, [10, 6, 3, 94, 125, 152, 210, 802, 3209, 10937, 58426, 166609, 341083, 203931], mark_line=["average"], legend_text_size=10, yaxis_label_textsize=8, yaxis_margin=2) return funnel, wordcloud, radar, pie, line
def countFinalWordsList(text, new_text): new_words = new_text.split(' ') countvaluelist = [] for i in new_words: #print i count = text.count(i) countvaluelist.append(count) funnel = Funnel("论坛评论词云统计图", width=900, height=700, title_pos='center') funnel.add("论坛评论词云统计", new_words, countvaluelist, is_label_show=True, label_pos="inside", label_text_color="#fff", funnel_sort="escending") funnel.render(r'../templates/ciyuncountwords.html')
def funnel(self, title=None, attr=None, value=None, two_title=None): """ 漏斗图 :param title: 数据可视化的标题(字符串) :param attr: 名称列表[列表] :param value: 名称列表对应数据 :param two_title: 二级小标题(鼠标悬浮显示小标题) :return:漏斗图 """ attr2 = attr value = value funnel = Funnel(title) funnel.add(two_title, attr2, value, is_label_show=True, label_pos='inside', label_text_color='#fff') self.page.add(funnel) self.page.render()
def get_top_skill(self,funnel_num=9): jieba.load_userdict('D:/编程练习题/datasite/test/analysis/user_dict.txt') unuse_keywords = ['开发', '工程师', ')', '(', ' ', '(', ')', '高级', '编号', '.', ':', '/', ':', '-', '职位', '+', '、', ',', '实习生', '..', '*', '_', '[', ']', '东莞', '3', '2', '二', '01', ',', ',', '2020', '一', '\\', '8k', '呼和浩特', '内蒙古', '07', 'ZHGAly' , 'J11797', '04', '05', '03', 'J11797', 'ZHGAljw', 'J11959', 'J12619', '对', '003', '002', '苏州', '&', '02', '.', '急聘', '应届生', '实习生', '月', '日' , '初级', '高级', '区域', '资深', '岗', '10', '实习', '五险一金', '讯飞', '大', '12K', '8K', '可', '双休', '出差', '平台', '福州', '方向', '北京', '推广' , '中级', '助理', '千', '总监', '客服', '客户', '省区', '与', '驻场', '合伙人', '商务', '专家', '讲师', '#', 'J11804', '年薪', '上市公司', '10W', '锁' , '员', '休闲', '娱乐', '医疗', '现场', '公安', '政府', '底薪', '负责人', '人事', '老师' , '五险', '一金', '重庆', '高新', '毕业生', '应届', '编程', '包', '合肥', '长期', '咨询', '师', '售后' , '小', '年', '程序员', 'RJ002', '号', '001', '个', '郑州', '武汉', '万', '招聘', '代表', '渠道', '4', '6', 'S', 'Y', '7', '5', '不' , '急', '++', '西安'] d = {} sql = 'select title,number from job' self.db.cursor.execute(sql) result = self.db.cursor.fetchall() for r in result: tmp = jieba.lcut(r[0]) for skill in tmp: if skill in unuse_keywords: continue if skill == '软件工程师': skill = '软件开发' if skill not in d.keys(): d[skill] = 0 d[skill] += int(r[1]) wordcloud = WordCloud(width=1000, height=600) wordcloud.add("", d.keys(), d.values(), word_size_range=[20, 100]) wordcloud.render(path="D:/编程练习题/datasite/test/templates/charts/wordcloud.html") d_order = sorted(d.items(), key=lambda x: x[1], reverse=True) d_order=dict(d_order[0:funnel_num]) configure(output_image=True) funnel = Funnel(background_color='white', title_text_size=20, title_pos='center',width=1000, height=600) funnel.add('教育', d_order.keys(), d_order.values(), is_label_show=True, label_pos='inside', is_legend_show=False) funnel.render(path='D:/编程练习题/datasite/test/templates/charts/career_funnel.html')
def test_funnel(): # label_pos 'inside' attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] funnel = Funnel("漏斗图示例") funnel.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") funnel.render() # label_pos 'outside'&legend_orient 'vertical' funnel = Funnel("漏斗图示例", title_pos='center') funnel.add("商品", attr, value, is_label_show=True, label_pos="outside", legend_orient='vertical', legend_pos='left') funnel.render()
def LouDou_2017(request): number = Area_gdp.objects.get(year=2017) attr = [ "北京", "天津", "河北", "山西", "内蒙古", "辽宁", "吉林", "黑龙江", "上海", "江苏", "浙江", "安徽", "福建", "江西", "山东", "河南", "湖北", "湖南", "广东", "广西", "海南", "重庆", "四川", "贵州", "云南", "西藏", "陕西", "甘肃", "青海", "宁夏", "新疆" ] value = [ number.beijing, number.tianjin, number.hebei, number.shanxi, number.neimenggu, number.liaoning, number.jilin, number.heilongjiang, number.shanghai, number.jiangsu, number.zhejiang, number.anhui, number.fujian, number.jiangxi, number.shandong, number.henan, number.hubei, number.hunan, number.guangdong, number.guangxi, number.hainan, number.chongqing, number.sichuan, number.guizhou, number.yunnan, number.xizang, number.shanxi, number.gansu, number.qinghai, number.ningxia, number.xinjiang ] funnel = Funnel("2017年地区经济数据分析", width=1500, height=600, title_pos='center') funnel.add( "GDP", attr, value, is_label_show=True, label_pos="outside", label_text_color="#fff", funnel_sort="ascending", # funnel_gap=5, legend_orient="vertical", legend_pos="left", ) funnel.render( path="F:/尚世康资料/尚世康+毕业论文相关资料/系统设计/cms/templates/2017年地区经济桶状图.html") return HttpResponse("2017年桶装图已生成")
is_label_show=True, is_piecewise=True, pieces=piece) map2.render("物料专配-省份分布.html") ##漏斗图 data_zhl = pd.read_excel(u"D:/code/Python/file/转化率作图.xlsx") attr = data_zhl.环节 values = data_zhl.总体转化率 funnel0 = Funnel('总体转化漏斗图', title_pos='center', width=2000, height=900) funnel0.add( name='环节', # 指定图例名称 attr=attr, # 指定属性名称 value=values, # 指定属性所对应的值 is_label_show=True, # 确认显示标签 label_formatter='{c}' + '%', # 指定标签显示的方式 legend_top='bottom', # 指定图例位置,为避免遮盖选择右下展示 # pyecharts包的文档中指出,当label_formatter='{d}'时,标签以百分比的形式显示. # 但我这样做的时候,发现显示的百分比与原始数据对应不上,只好用上面那种显示形式 label_pos='outside', # 指定标签的位置,inside,outside legend_orient='vertical', # 指定图例显示的方向 legend_pos='right') # 指定图例的位置 funnel0.render("转化漏斗.html") ##pyecharts仓网覆盖连线 path = u"D:/物料专配/2.0/8.25版/4、7、10仓结果/C_Network_10_0826.csv" data_pyfugai = pd.read_csv(open(path)) #获取RDC仓位置和城市经纬度坐标点 RDC_cords = { data_pyfugai.iloc[i]['RDC_NAME']: [data_pyfugai.iloc[i]['RDC_LGT'], data_pyfugai.iloc[i]['RDC_LAT']]
# v2=[listOA[0]] # radar =Radar() # radar.config(schema) # radar.add("全体信件总处理量", v1, is_splitline=True, is_axisline_show=True) # radar.add("校领导信箱处理量", v2, label_color=["#4e79a7"], is_area_show=False,is_label_show=True) # radar.show_config() # radar.render('radar.html') from pyecharts import Funnel attr = keyNameList value = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] for i in range(27): for j in range(9): value[i] += listOA[i][j] funnel = Funnel('各部门截止目前2017年处理总量金字塔', title_pos='center', width=1200, height=800) funnel.add('infomation', attr, value, is_label_show=True, label_pos="inside", label_text_color='#999', legend_orient='vertical', legend_pos='left') funnel.render('funnel.html')
# -*- coding: utf-8 -*- """ Created on Thu Aug 10 18:07:30 2017 @author: 17549 """ from pyecharts import Funnel attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] funnel = Funnel("动态漏图", width=600, height=400, title_pos='center') funnel.add("商品", attr, value, is_label_show=True, label_pos="outside", legend_orient='vertical', legend_pos='left') funnel.show_config() funnel.render(r"E:\12_动态漏图升级.html")
tokens=[token for token in cun if token not in stops] d={} for i in tokens: d[i] = d.get(i,0) + 1 count_list = sorted(d.items(), key=lambda x:x[1], reverse=True) count_list = count_list[:15] keyword_list = [k[0] for k in count_list] value_list = [k[1] for k in count_list] funnel=Funnel(background_color='#404a59') #修改标题位置 funnel.use_theme("dark") #修改图表主题 funnel.add("",keyword_list, value_list, is_label_show=True, is_legend_show=False, label_pos="outside") #是否显示标签、是否显示图例、标签位置 funnel._option['series'][0]["top"]=70 #修改漏斗图上间隔 funnel._option['series'][0]["bottom"]=20 #修改漏斗图下间隔 funnel._option['series'][0]["left"]="5%" #修改漏斗图左间隔 funnel._option['series'][0]["width"]="90%" #修改漏斗图宽度 #funnel.render(r"D:\BI大屏\漏斗图.html") page.add_chart(funnel,name="funnel") #============================================================================= # 关系图 from pyecharts import Graph #=============================================================================
from pyecharts import Funnel attr = ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'] value = [20, 40, 60, 80, 100, 120] funnel = Funnel('漏斗图') funnel.add('商品', attr, value, is_label_show=True, label_pos='inside', label_text_color='#fff') funnel.render()
print('多数用户复购次数:{}次'.format((date_rebuy-1).mode()[0])) plt.show()''' #(四)漏斗分析-流失率 data_user_count = data_user.groupby('behavior_type')['behavior_type'].count() pv_all = data_user['user_id'].count() print(data_user_count) print("总浏览量:",pv_all) print('总浏览量—点击量 流失率: {:.2f}'.format((pv_all-502835)/pv_all)) print("点击量-加入购物车量 流失率:{:.2f}".format((502835-10756)/502835)) print("加入购物车量-收藏量 流失率:{:.2f}".format((10756-14896)/10756)) print("收藏量-购买量 流失率:{:.2f}".format((14896-5195)/14896)) from pyecharts import Funnel funnel = Funnel("漏斗分析", width=600, height=400, title_pos='center') funnel.add("用户行为数据", ['点击','收藏','加入购物车','支付'],[502835,10756,14896,5195], is_label_show=True,label_formatter='{b} {c}',label_pos="outside",legend_orient='vertical', legend_pos='left') funnel.render('E:/python/data/user_behavior_analysis_tb/data.html') # (五)用户价值度分析 from datetime import datetime datenow = datetime(2014,12,20) # 计算每位用户最近购买时间 recent_buy_time = data_user[data_user.behavior_type==4].groupby('user_id')\ .date.apply(lambda x:datetime(2014,12,20)-x.sort_values().iloc[-1])\ .reset_index().rename(columns={'date':'recent'}) recent_buy_time.recent = recent_buy_time.recent.map(lambda x:x.days) # 计算每位用户消费频率 buy_freq = data_user[data_user.behavior_type==4].groupby('user_id').date.count().\ reset_index().rename(columns={'date':'freq'}) # 将最近购买时间和消费频率合并在一起 rfm = pd.merge(recent_buy_time,buy_freq,left_on='user_id',right_on='user_id',how='outer')
from pyecharts import Funnel #选项 attr = ["美女", '房子', '车子', '事业', '家人', '娱乐', '数码产品'] #权重 value = [150, 100, 80, 120, 140, 90, 70] #新建一个漏斗图 funnel = Funnel("男人心漏斗图") # 数据 权重 边缘标签 中间标签 funnel.add("因素", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") funnel.render(r'C:\Users\Administrator\Desktop\数据可视化\pyecharts\html\8.html')
sqlDF = spark.sql( "SELECT count(pv) as cpv, count(cart) as ccart, count(fav) as cfav, count(buy) as cbuy from pbcf" ) sqlDF.show() pbcfPandasDF = sqlDF.toPandas() # Python实现漏斗图的绘制 https://blog.csdn.net/qq_41080850/article/details/83933017 from pyecharts import Funnel attrs = pd.Series(['pv', 'cart', 'fav', 'buy']).tolist() attr_value = pd.Series([ 100, pbcfPandasDF.iloc[0]['ccart'] / pbcfPandasDF.iloc[0]['cpv'] * 100, pbcfPandasDF.iloc[0]['cfav'] / pbcfPandasDF.iloc[0]['ccart'] * 100, pbcfPandasDF.iloc[0]['cbuy'] / pbcfPandasDF.iloc[0]['ccart'] * 100 ]).tolist() funnel1 = Funnel("总体转化漏斗图一", width=800, height=400, title_pos='center') funnel1.add( name="商品交易行环节", # 指定图例名称 attr=attrs, # 指定属性名称 value=attr_value, # 指定属性所对应的值 is_label_show=True, # 指定标签是否显示 label_formatter='{c}%', # 指定标签显示的格式 label_pos="inside", # 指定标签的位置 legend_orient='vertical', # 指定图例的方向 legend_pos='left', # 指定图例的位置 is_legend_show=True) # 指定图例是否显示 funnel1.render() funnel1 spark.catalog.clearCache() spark.stop()