From d47dcf0080af8995a2d9dc52b16bc7a5dba5bca8 Mon Sep 17 00:00:00 2001 From: p6mtf24ic Date: Wed, 27 Apr 2022 21:38:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E6=9E=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Untitled1.py | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 Untitled1.py diff --git a/Untitled1.py b/Untitled1.py new file mode 100644 index 0000000..4519b4d --- /dev/null +++ b/Untitled1.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[2]: + + + +import jieba +import pandas as pd + +import xlwt + +from pyecharts import options as opts +from pyecharts.charts import Pie +from pyecharts.commons.utils import JsCode + + + +df_tb=pd.read_excel("D:\\python code\\分布式爬虫\\jd\\shuju1.xlsx") +df_tb.drop_duplicates(inplace=True) +price_list=[] +for price in df_tb['price']: + price_list.append(price) + +A=0 +B=0 +C=0 +D=0 +E=0 +F=0 +for price in price_list: + if price<30 : + A+=1 + elif price<50 : + B+=1 + elif price<80 : + C+=1 + elif price<120 : + D+=1 + elif price<200 : + E+=1 + else: + F+=1 + + +sum=A+B+C+D+E+F + +total_cup=sum +fn = """ + function(params) { + if(params.name == 'other') + return '\\n\\n\\n' + params.name + ' : ' + params.value + '%'; + return params.name + ' : ' + params.value + '%'; + } + """ + + +def new_label_opts(): + return opts.LabelOpts(formatter=JsCode(fn), position="center") + + +pie = ( + Pie() + .add( + "", + [['A_0到30元', round((round(A/total_cup, 2)*100),2)],['other',round(1 -A/total_cup, 2)*100]], + center=["10%", "30%"], + radius=[60, 80], + label_opts=new_label_opts(), + ) + .add( + "", + [['B_30到50元', round((round(B/total_cup, 2)*100),2)],['other',round(1 - B/total_cup, 2)*100]], + center=["35%", "30%"], + radius=[60, 80], + label_opts=new_label_opts(), + ) + .add( + "", + [['C_50到80元', round((round(C/total_cup, 2)*100),2)],['other',round(1 - C/total_cup, 2)*100]], + center=["60%", "30%"], + radius=[60, 80], + label_opts=new_label_opts(), + ) + .add( + "", + [['D_80到120元', round((round(D/total_cup, 2)*100),2)],['other',round(1 - D/total_cup, 2)*100]], + center=["10%", "70%"], + radius=[60, 80], + label_opts=new_label_opts(), + ) + .add( + "", + [['E_120到200元', round((round(E/total_cup * 100, 2)),0)],['other',round(1 - E/total_cup, 2)*100]], + center=["35%", "70%"], + radius=[60, 80], + label_opts=new_label_opts(), + ) + .add( + "", + [['F_200元以上', round((round(F/total_cup * 100, 2)),0)],['other',round(1 - F/total_cup, 2)*100]], + center=["60%", "70%"], + radius=[60, 80], + label_opts=new_label_opts(), + ) + .set_global_opts( + title_opts=opts.TitleOpts(title="Cup-多饼图"), + legend_opts=opts.LegendOpts( + type_="scroll", pos_top="20%", pos_left="80%", orient="vertical" + ), + ) +) + +pie.render("pie_demo.html") + + + + + +