You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
2.6 KiB
121 lines
2.6 KiB
#!/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")
|
|
|
|
|
|
|
|
|
|
|
|
|