Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python data Visualization to analyze user retention rate

Shulou Source: shulou.com Published: 2022-06-03 10:03:08 10月03日 Update

How to use Python data visualization to analyze the user retention rate, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

About "funnel chart"

Funnel chart is often used to analyze the conversion rate of user behavior, for example, funnel chart is used to analyze the conversion rate of each link in the user purchase process. Of course, in the whole process of analysis, we will put together the funnel diagrams before and after process optimization, compare and analyze them, and draw relevant conclusions. Today, the editor will use the modules of "matplotlib", "plotly" and "pyecharts" to demonstrate how to draw a good funnel diagram. First of all, we have to import the modules and data that we need to use.

Import matplotlib.pyplot as plt import pandas as pd df = pd.DataFrame ({"Link": ["Link 1", "Link 2", "Link 3", "Link 4", "Link 5"], "number": [1000, 600,400,250,100], "overall conversion rate": [1.00,0.60,0.40,0.25,0.1]})

The data to be used is shown below:

Using matplotlib to make the funnel diagram, the effect may be a little simple and rough, and the principle of the production is also relatively simple. First draw the horizontal histogram, and then use the "left" parameter in plot.barh () to move the histogram to the left, which is similar to the funnel diagram.

Y = [5 idx 4, idx 3, left 1] x = [85, 75, 58, 43] x_min = 0 for idx, val in enumerate (x): plt.barh (y [idx], x [idx], left = idx+5) plt.xlim (x_min, x_max)

To draw the shape of the funnel we want, the code example is as follows

From matplotlib import font_manager as fm # funnel chart y = [5, figsize= 4] labels = df ["link"]. Tolist () x = df ["number"]. Tolist () x_range = 100 font = fm.FontProperties (fname= "KAITI.ttf") fig, ax = plt.subplots (1, figsize= (12)) for idx, val in enumerate (x): left = (x_range-val) / 2 plt.barh (y [idx], x [idx], left = left, color='#808B96', height=.8) Edgecolor='black') # label plt.text (50, y [idx] + 0.1, labels [idx], ha='center', fontproperties=font, fontsize=16, color='#2A2A2A') # value plt.text (50, y [idx]-0.3, x [idx], ha='center', fontproperties=font, fontsize=16 Color='#2A2A2A') if idx! = len (x)-1: next_left = (x_range-x [idx+1]) / 2 shadow_x = [left, next_left, 100-next_left, 100-left, left] shadow_y = [y [IDX]-0.4, y [idx+1] + 0.4, y [idx+1] + 0.4 Y [idx]-0.4, y [IDX]-0.4] plt.plot (shadow_x, shadow_y) plt.xlim (x_min, x_max) plt.axis ('off') plt.title (' turnover rate of each link', fontproperties=font, loc='center', fontsize=24, color='#2A2A2A') plt.show ()

The funnel drawing is shown in the following figure

Of course, it would be easier for us to draw with plotly. The code example is as follows

Import plotly.express as px data = dict (values=, labels= ['Link one', 'Link two', 'Link three', 'Link four', 'Link five']) fig = px.funnel (data, yawning labelsgiving, xerograms values) fig.show ()

Finally, we use the pyecharts module to draw, in which there is a special method to draw the "funnel diagram", we just need to call it.

From pyecharts.charts import Funnel from pyecharts import options as opts from pyecharts.globals import ThemeType c = (Funnel (init_opts=opts.InitOpts (width= "900px", height= "600px", theme = ThemeType.INFOGRAPHIC)) .add ("link", df [["link", "overall conversion rate"]] .values, sort_= "descending", label_opts=opts.LabelOpts (position= "inside") ) .set _ global_opts (title_opts=opts.TitleOpts (title= "Pyecharts funnel chart", pos_bottom = "90%", pos_left = "center")) c.render_notebook ()

After we label the data,

C = (Funnel (init_opts=opts.InitOpts (width= "900px", height= "600px", theme = ThemeType.INFOGRAPHIC)) .add ("Commodity", df [["links", "overall conversion rate"] .values, sort_= "descending", label_opts=opts.LabelOpts (position= "inside"), .set _ global_opts (title= "Pyecharts funnel chart") Pos_bottom = "90%", pos_left = "center") .set _ series_opts (label_opts=opts.LabelOpts (formatter= "{b}: {c}")) c.render_notebook ()

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Links funnels analysis conversion rate data users totals modules production number of people code appearance flow histogram examples help visualization good-looking clear rough Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info Apple Microsoft Linux