In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to draw Pareto map with Python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to draw a Pareto map with Python.
# Random colors, from fakerdef rand_color ()-> str: return random.choice (["# c23531", "# 2f4554", "# 61a0a8", "# d48265", "# 749f83", "# ca8622", "# bda29a", "# 6e7074", "# 546570") "# c4ccd3", "# f05b72", "# 444693", "# 726930", "# b2d235", "# 6d8346", "# ac6767", "# 1d953f", "# 6950a1",]) df_origin = pd.DataFrame ({'categories': ["vegetables", "fruits") "Pork", "e-commerce", "synthesis", "aquatic products"], 'sales': [random.randint (10,100) for _ in range (6)]}) print (df_origin) # in descending order of sales df_sorted = df_origin.sort_values (by='sales') Ascending=False) print (df_sorted) # Line chart x axis x_line_categories = [* range (7)] # Line chart y axis-downward cumulative frequency cum_percent = df_sorted ['sales'] .cumsum () / df_sorted [' sales'] .sum () * 100cum_percent = cum_percent.append (pd.Series ([0])) # add the starting frequency 0cum_percent = cum_percent.sort_values (ascending=True) print ( Df_sorted.categories.values.tolist () print (cum_percent.values.tolist ()) def pareto_bar ()-> Bar: line = (Line () .add _ xaxis (x_line_categories) .add _ yaxis (cumulative percentage) Cum_percent.values.tolist (), xaxis_index=1, yaxis_index=1, # use secondary y axis That is, extend_axis label_opts=opts.LabelOpts (is_show=False), is_smooth=True,)) bar = (Bar () .add _ xaxis (df_sorted.categories.values.tolist ()) .add _ yaxis ('sales', df_sorted.sales.values.tolist ()) in bar Category_gap=0) # .add _ yaxis ('percentage of total amount', cum_percent.values.tolist ()) .extend _ axis (xaxis=opts.AxisOpts (is_show=False, position='top')) .extend _ axis (yaxis=opts.AxisOpts (axistick_opts=opts.AxisTickOpts (is_inside=True), # scale facing inward axislabel_opts=opts.LabelOpts (formatter=' {value}%')) Position='right') .set _ series_opts (label_opts=opts.LabelOpts (is_show=True, font_size=14)) .set _ global_opts (title_opts=opts.TitleOpts (title=' Pareto example-sales\ n Make By tengyulong', subtitle=''), xaxis_opts=opts.AxisOpts (name=' item Type', type_='category') Yaxis_opts=opts.AxisOpts (axislabel_opts=opts.LabelOpts (formatter= "{value} pieces") bar.overlap (line) return barpareto_bar (). Render ('Pareto map .html') # or pareto_bar () .render_notebook ()
Render effect:
At this point, I believe you have a deeper understanding of "how to draw a Pareto map with Python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.