guopengfa
发布于 2020-05-08 / 573 阅读 / 0 评论 / 0 点赞

Pyecharts实战,全局参数,各种参数

from pyecharts.charts import Bar, Line, Page
from pyecharts import options as opts
from pyecharts.globals import ThemeType
from pyecharts.options import LabelOpts, TitleOpts, DataZoomOpts, AxisOpts
import pandas as pd
import pyecharts

#FBA四段库存和日销库存推移图
def siduan_table(csv):
datasource = pd.read_csv(csv,encoding = "gbk",)
options = opts.InitOpts(theme=ThemeType.LIGHT,width = "2000px",height = "800px")
bar = Bar(options)
bar_x = []
for i in datasource.keys()[1:]:
bar_x.append(i)
bar.add_xaxis(bar_x)
# bar.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_size=10, interval=0)))#设置x轴显示所有数据
bar.set_global_opts(title_opts=TitleOpts(title="\n\nFBA四段库存和日销库存推移图",pos_right="center"))
#shape:(9, 33)
inbase = []
inland = []
FBA_TX_inbase_price = []
FBA_HM_inbase_price = []
FBA_TX_inland_price = []
FBA_HM_inland_price = []
FBA_sell_day_o = []
FBA_inbase_inland_o = []
result = []

for row in range(len(bar_x)):
    bar_y = datasource[bar_x[row]].to_list()
    inbase.append(bar_y[0])
    inland.append(bar_y[1])
    FBA_TX_inbase_price.append(bar_y[2])
    FBA_HM_inbase_price.append(bar_y[3])
    FBA_TX_inland_price.append(bar_y[4])
    FBA_HM_inland_price.append(bar_y[5])
    FBA_sell_day_o.append(bar_y[6])
    FBA_inbase_inland_o.append(bar_y[7])
    result.append(round(bar_y[8],2))
bar.add_yaxis("亚马逊FBA在库金额",inbase,stack="stack1",label_opts=LabelOpts(False))
bar.add_yaxis("亚马逊FBA在途金额",inland,stack="stack1",label_opts=LabelOpts(False))
bar.add_yaxis("FBA虚拟仓_塘厦在库库存金额",FBA_TX_inbase_price,stack="stack1",label_opts=LabelOpts(False))
bar.add_yaxis("FBA虚拟仓_虎门在库库存金额", FBA_HM_inbase_price,stack="stack1",label_opts=LabelOpts(False))
bar.add_yaxis("FBA虚拟仓_塘厦采购在途金额", FBA_TX_inland_price, stack="stack1",label_opts=LabelOpts(False))
bar.add_yaxis("FBA虚拟仓_虎门采购在途金额", FBA_HM_inland_price, stack="stack1",label_opts=LabelOpts(False))
line = Line()
line.add_xaxis(bar_x)
line.add_yaxis("FBA日销库金额+产品附加值",FBA_sell_day_o,label_opts=LabelOpts(False))
line.add_yaxis("亚马逊FBA在库+在途+产品附加值",FBA_inbase_inland_o,label_opts=LabelOpts(False))
line.add_yaxis("合计",result,label_opts=LabelOpts(margin=5))
bar.overlap(line)
return bar

#FBA断货listing计数及占比推移图
def FBAlistingPR(csv):
data_source = pd.read_csv(csv,encoding="gbk",sep="\t")
options = opts.InitOpts(theme=ThemeType.LIGHT, width="2000px", height="800px")
bar = Bar(options)
bar.extend_axis(yaxis=AxisOpts())
bar.set_global_opts(title_opts=TitleOpts("\n\nFBA断货listing计数及占比推移图",pos_left="center"))
bar_x = []
for table_name in data_source.keys()[1:]:
bar_x.append(table_name)
bar.add_xaxis(bar_x)
inbase = []
inland = []
listingnum = []
commonlisting = []
rate = []
for row in range(len(bar_x)):
bar_y = data_source[bar_x[row]].to_list()
listingnum.append(bar_y[0])
commonlisting.append(bar_y[1])
rate.append(float(bar_y[2].replace("%","")))
bar.add_yaxis("断货listing计数",listingnum,label_opts=LabelOpts(is_show=False))
option = opts.InitOpts(theme = ThemeType.LIGHT,width="2000px",height="800px")
line = Line(option)
line.add_xaxis(bar_x)
line.add_yaxis("占比%",rate,yaxis_index=1)
line.render(r"D:\Python\数据分析\rsult\line.html")
bar.overlap(line)
return bar
#FBA模拟断货天数的销库金额及占比推移图
def FBAlistingMPR(csv):
data_source = pd.read_csv(csv, encoding="gbk", sep="\t")
options = opts.InitOpts(theme=ThemeType.LIGHT, width="2000px", height="800px")
bar = Bar(options)
bar.extend_axis(yaxis=AxisOpts())
bar.set_global_opts(title_opts=TitleOpts("\n\nFBA模拟断货天数的销库金额及占比推移图", pos_left="center"))
bar_x = []
for table_name in data_source.keys()[1:]:
bar_x.append(table_name)
bar.add_xaxis(bar_x)
inbase = []
inland = []
listingnum = []
commonlisting = []
rate = []
for row in range(len(bar_x)):
bar_y = data_source[bar_x[row]].to_list()
listingnum.append(bar_y[0])
commonlisting.append(bar_y[1])
rate.append(round(bar_y[2]*100,2))
bar.add_yaxis("断货listing计数", listingnum, label_opts=LabelOpts(is_show=False))
option = opts.InitOpts(theme=ThemeType.LIGHT, width="2000px", height="800px")
line = Line(option)
line.add_xaxis(bar_x)
line.add_yaxis("占比%", rate, yaxis_index=1)
bar.overlap(line)
return bar

FBA按销量段模拟断货天数的销库金额推移(单位:万)

def FBAMnumSellMo(csv):
data_source = pd.read_csv(csv,encoding = "gbk",sep = "\t")
options = opts.InitOpts(theme=ThemeType.LIGHT, width="2000px", height="800px")
bar = Bar(options)
bar_x = []
for table_name in data_source.keys()[1:]:
bar_x.append(table_name)
bar.add_xaxis(bar_x)
bar.extend_axis(yaxis=AxisOpts())
a_sell = []
# A.微销0 < 日均销量 < 0.1
b_sell = []
# B.弱销(0.1 <= 日均销量 < 0.3)
c_sell = []
# C.低销(0.3 <= 日均销量 < 0.6)
d_sell = []
# D.平销(0.6 <= 日均销量 < 1)
e_sell = []
# E.中销(1 <= 日均销量 < 3)
f_sell = []
# F.高销(3 <= 日均销量 < 5)
g_sell = []
# G.畅销(5 <= 日均销量 < 10)
h_sell = []
# H.热销(10 <= 日均销量 < 20)
i_sell = []
# I.爆款(日均销量 >= 20)
count_sell = []
# 合计
for row_num in range(len(bar_x)):
bar_y = data_source[bar_x[row_num]].to_list()
a_sell.append(bar_y[0])
b_sell.append(bar_y[1])
c_sell.append(bar_y[2])
d_sell.append(bar_y[3])
e_sell.append(bar_y[4])
f_sell.append(bar_y[5])
g_sell.append(bar_y[6])
h_sell.append(bar_y[7])
i_sell.append(bar_y[8])
count_sell.append(bar_y[9])
bar.add_yaxis("A.微销0 < 日均销量 < 0.1",a_sell,label_opts=LabelOpts(is_show=False),stack="stack1")
bar.add_yaxis("B.弱销(0.1 <= 日均销量 < 0.3)", b_sell, label_opts=LabelOpts(is_show=False),stack="stack1")
bar.add_yaxis("C.低销(0.3 <= 日均销量 < 0.6)", c_sell, label_opts=LabelOpts(is_show=False),stack="stack1")
bar.add_yaxis("D.平销(0.6 <= 日均销量 < 1)", d_sell, label_opts=LabelOpts(is_show=False), stack="stack1")
bar.add_yaxis("E.中销(1 <= 日均销量 < 3)", e_sell, label_opts=LabelOpts(is_show=False), stack="stack1")
bar.add_yaxis("F.高销(3 <= 日均销量 < 5)", f_sell, label_opts=LabelOpts(is_show=False), stack="stack1")
bar.add_yaxis("G.畅销(5 <= 日均销量 < 10)", g_sell, label_opts=LabelOpts(is_show=False), stack="stack1")
bar.add_yaxis("H.热销(10 <= 日均销量 < 20)", h_sell, label_opts=LabelOpts(is_show=False), stack="stack1")
bar.add_yaxis("I.爆款(日均销量 >= 20)", i_sell, label_opts=LabelOpts(is_show=False), stack="stack1")
line = Line(options)
line.add_xaxis(bar_x)
line.add_yaxis("合计",count_sell,yaxis_index=1)
bar.overlap(line)
bar.set_global_opts(title_opts=TitleOpts(title="\n\nFBA按销量段模拟断货天数的销库金额推移(单位:万)",pos_left="center"))
return bar

FBA模拟断货天数的销量数据及占比推移图

def FBAlistingNPR(csv):
data_source = pd.read_csv(csv, encoding="gbk", sep="\t")
options = opts.InitOpts(theme=ThemeType.LIGHT, width="2000px", height="800px")
bar = Bar(options)
bar.extend_axis(yaxis=AxisOpts())
bar.set_global_opts(title_opts=TitleOpts("\n\nFBA模拟断货天数的销库金额及占比推移图", pos_left="center"))
bar_x = []
for table_name in data_source.keys()[1:]:
bar_x.append(table_name)
bar.add_xaxis(bar_x)
inbase = []
inland = []
listingnum = []
commonlisting = []
rate = []
for row in range(len(bar_x)):
bar_y = data_source[bar_x[row]].to_list()
listingnum.append(bar_y[0])
commonlisting.append(bar_y[1])
rate.append(round(bar_y[2]*100,2))
bar.add_yaxis("断货listing计数", listingnum, label_opts=LabelOpts(is_show=False))
option = opts.InitOpts(theme=ThemeType.LIGHT, width="2000px", height="800px")
line = Line(option)
line.add_xaxis(bar_x)
line.add_yaxis("占比%", rate, yaxis_index=1)
bar.overlap(line)
return bar
#FBA按销量段断货listing占比数据推移
def FBAsellBlistingrata(csv):
data_source = pd.read_csv(csv,encoding = "gbk",sep = "\t")
options = opts.InitOpts(theme = ThemeType.LIGHT,width="2000px",height="800px")
line = Line(options)
line_x = []
for tablename in data_source.keys()[1:]:
line_x.append(tablename)
line.add_xaxis(line_x)
value_name = data_source["FBA断货"].to_list()
data_source = data_source.T
for value in range(len(value_name)):
line_y = data_source[value].to_list()
for num in range(len(line_y)):
if num>0:
line_y[num] = round(line_y[num]*100,2)
line.add_yaxis(line_y[0],line_y[1:],stack="stack1")
line.set_global_opts(title_opts=TitleOpts("\n\nFBA按销量段断货listing占比数据推移",pos_left="center"))
return line
if name == 'main':
page = Page("图标展示")
page.add(siduan_table("D:\Python\数据分析\datasource\FBA四段库存和日销库存推移图.csv"))
page.add(FBAlistingPR("D:\Python\数据分析\datasource\FBA断货listing计数及占比推移图.csv"))
page.add(FBAlistingMPR("D:\Python\数据分析\datasource\FBA模拟断货天数的销库金额及占比推移图.csv"))
page.add(FBAMnumSellMo("D:\Python\数据分析\datasource\FBA按销量段模拟断货天数的销库金额推移(单位万).csv"))
page.add(FBAlistingNPR("D:\Python\数据分析\datasource\FBA模拟断货天数的销量数据及占比推移图.csv"))
page.add(FBAsellBlistingrata("D:\Python\数据分析\datasource\FBA按销量段断货listing占比数据推移.csv"))
page.add(FBAsellBlistingrata("D:\Python\数据分析\datasource\FBA按销量段模拟断货天数的销量占比推移图.csv").set_global_opts(title_opts=TitleOpts("\n\nFBA按销量段模拟断货天数的销量占比推移图",pos_left="center")))
page.render(r"D:\Python\数据分析\rsult\输出测试.html")


评论