Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to deal with Excel data

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use Python to deal with Excel data". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Load the data from Excel first:

# load data import pandas as pddf = pd.read_excel (r "D:\ my document\ MySQL.xlsx", sheet_name = 1) df

two。 Simply do some data cleaning:

# sort descending df.sort_values by num field (by = "num", ascending = False)

3. Make a visual output

3.1 draw a single series of bar charts and briefly compare the sales (quantity) of various fruit products.

From pyecharts.charts import Barfrom pyecharts import options as optsc = (# create histogram object and set the size, or not, use the default size to Bar (init_opts=opts.InitOpts (width= "700px", height= "500px")) # set the X-axis data series, only take the first 10 data, and convert to the list format. Add _ xaxis (df.goods [: 10] .tolist ()) # set Y-axis data series and display color Take only the first 10 data And convert to list format .add _ yaxis ("sales quantity", df.num [: 10] .tolist ()) # set the title and location of the chart. Set _ global_opts (title_opts=opts.TitleOpts (title= "sales quantity of TOP10 fruit items" Pos_left= "left")) # render the column chart to html# .render ("bar chart .html") in Web by render () method) # render c.render_notebook () directly in notebook ()

Render effect:

3.2 draw a column chart of a multi-data series in order to compare and analyze the sales amount & sales quantity of various fruits

# the effect of drawing a multi-data series column chart is as follows: from pyecharts.charts import Barfrom pyecharts import options as optsc = (# create a column object and set the size, or you can directly use the default size to Bar (init_opts=opts.InitOpts (width= "900px", height= "500px")) # set the X-axis data series, taking only the first 10 data And convert to list format .add _ xaxis (df.goods [: 10] .tolist ()) # set Y-axis data series and display color, only take the first 10 data And convert to list format .add _ yaxis ("sales amount", df.money [: 10] .tolist ()) .add _ yaxis ("sales quantity", df.num [: 10] .tolist ()) # set the title and location of the chart. Set _ global_opts (title_opts=opts.TitleOpts (title= "sales performance of TOP10 fruit items" Pos_left= "left")) # render the column chart to html# .render ("bar chart .html") in Web by render () method) # render c.render_notebook () directly in notebook ()

Render effect:

Change color for column color = "RGB value / hexadecimal color code / image color / acronym"

From pyecharts.charts import Barfrom pyecharts import options as optsc = (# create histogram object and set the size, or not, use the default size to Bar (init_opts=opts.InitOpts (width= "700px", height= "500px")) # set the X-axis data series, only take the first 10 data, and convert to the list format. Add _ xaxis (df.goods [: 10] .tolist ()) # set Y-axis data series and display color Take only the first 10 data And convert to list format .add _ yaxis ("sales quantity", df.num [: 10] .tolist (), color = "RGB (0,0,255)") # set the title and location of the chart. Set _ global_opts (title_opts=opts.TitleOpts (title= "sales quantity of TOP10 fruit items") Pos_left= "left")) # render the column chart to html# .render ("histogram .html") in Web through the render () method) # render directly in notebook c.render_notebook () "how to use Python to process Excel data" ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report