pyechart实现双柱双线及交互式漏斗图

1.双线双柱图,这个用pyecharts好实现,用tableau稍微有点麻烦,记录下。运行过程中,代码因pyecharts版本问题可能会报错,我的解决方式是直接pip install 安装老的版本。

import pandas as pd 
import pyecharts as pec

data = pd.read_excel(r'xxx.xlsx')
data = data.drop([len(data)-2,len(data)-1])
data = pd.concat([data.iloc[1::-1,:],data.iloc[2:,:]])
names = data.columns

attr = ["{}时".format(i) for i in range(8,21)]
  
bar = pec.Bar('标题1',width =1500,height= 600)
bar.add('变量1',attr, data.ix[:,1],is_label_show=False )
bar.add('变量2',attr, data.ix[:,2],mark_line=["average"])
bar.add('变量3',attr, data.ix[:,len(names)-1])

line = pec.Line()
for i in range(4,len(names)-1):
    line.add(names[i],attr,data.iloc[:,i])
 
overlap = pec.Overlap()
overlap.add(bar)
overlap.add(line, yaxis_index=1, is_add_yaxis = True)
overlap.show_config()
overlap.render('./times.html')

print(data.describe().round(1))

  

2.交互式漏斗图

names = ['weeks','count(behavior_type)','点击次数','收藏次数','加购数','购买次数']
data = pd.read_csv('E:/Pro/weeks.csv',header=None,names = names)

attr = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']


bar = pec.Bar('用户行为-周图',width =1500,height= 600)
bar.add('用户行为总数量',attr, data.iloc[:,1],is_label_show=False)
bar.add('点击总量',attr, data.iloc[:,2])

line = pec.Line()
for i in range(3,len(names)):
	line.add(names[i],attr,data.iloc[:,i])

overlap = pec.Overlap()
overlap.add(bar)
overlap.add(line, yaxis_index=1, is_add_yaxis = True)
overlap.show_config()
overlap.render('./weeks.html')

  

上一篇:Java项目:嘟嘟网上商城系统(java+jdbc+jsp+mysql+ajax)


下一篇:pywebio 和 pyecharts天生一对