In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how Python Pyecharts draws Sanji diagram to analyze user behavior path". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to draw Python Pyecharts diagram to analyze user behavior path" can help you solve the problem.
Sanji diagram, its core is to connect different points through lines. The thickness of the line represents the size of the flow. A lot of tools can achieve Sankey.
Graphs, such as Excel, tableau, we are going to use Pyecharts to draw today.
Since there is no public data related to the user behavior path, this visualization is based on the Titanic, its survival and the victims.
Data to analyze the flow path. Learn to think, and you can also change it to your own company's user behavior and bury some data.
Read data from pyecharts import options as optsfrom pyecharts.charts import Sankeyimport pandas as pddata = pd.read_excel ('/ Users/wangwangyuqing/Desktop/train.xlsx') data
Organize the data structure: parent class → subclass → value
From the parent class to the subclass, every two adjacent classification variables need to be calculated. Using the PivotTable in Pandas, the calculated data is vertically merged into three columns.
Lis = data.columns.tolist () [:-1] lis1 = lis [:-1] lis2 = lis1:] data1 = pd.DataFrame () for i in zip (lis1,lis2): datai = data.pivot_table ('ID',index=list (I), aggfunc='count'). Reset_index () datai.columns= [0mem1m2] data1 = data1.append (datai) data1
Generate node data
All the nodes involved need to be reorganized together. List in the form of nested dictionaries to re-summarize.
# generate nodesnodes = [] # first add several top-level parent nodes nodes.append ({'name':'C port'}) nodes.append ({'name':'Q port'}) nodes.append ({'name':'S port'}) # add other nodes for i in data1 [1] .unique (): dic = {} dic ['name'] = I nodes.append (dic) nodes
Organizing data: defining nodes and traffic
Where does the data flow from, what is the flow (value), loop + dictionary to organize the data
Links = [] for i in data1.values: dic = {} dic ['source'] = I [0] dic [' target'] = I [1] dic ['value'] = I [2] links.append (dic) links
Data visualization c = (Sankey (init_opts=opts.InitOpts (width= "1200px", height= "800px", theme='westeros')) .add ("", nodes=nodes, links=links, linestyle_opt=opts.LineStyleOpts (opacity=0.2, curve=0.5, color= "source"), label_opts=opts.LabelOpts (position= "right") ) .set _ global_opts (title_opts=opts.TitleOpts (title= "Sanji diagram") .render ("/ Users/wangwangyuqing/Desktop/image.html"))
Sanji diagram is one of the effective methods to analyze the user path, which can directly show the user's journey, help us to further determine the key steps in the conversion funnel and discover the user's
Loss point, find valuable user groups, see where users mainly flow, find users' points of interest and neglected product value, and look for new opportunities.
This is the end of the content about "how Python Pyecharts draws Sanji diagrams to analyze user behavior paths". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.