Python data analysis practice: use pyecharts to draw the proportion of consumption categories

Part of the data source: ChatGPT 

What is a puzzle?

Pie Chart, also known as a pie chart or a pie chart, is a chart that expresses the proportion of values ​​​​through the size of the sector.

How to draw a puzzle using pyecharts?

In Python, we can use the pyecharts library to draw various charts, including puzzles. To use pyecharts, we need to install it first. You can run the following command at the command line to install:

pip install pyecharts

After the installation is complete, we can start to use pyecharts to draw the puzzle.

Example: Use a puzzle to show the proportion of consumption categories

In the following example, we will use pyecharts to create a mosaic of the proportion of consumption categories, showing the proportion of different categories of consumption for a small merchant over a period of time.

We save the data in a file in csv format. The file contains the following columns:

  • date: consumption date;
  • category: consumption category;
  • amount: consumption amount.

Feel free to write some sample data into it first data.csv:

date,category,amount
2023-06-01,餐饮,88
2023-06-02,文具,23
2023-06-03,服装,98
2023-06-04,餐饮,43
2023-06-05,文具,67
2023-06-06,餐饮,100
2023-06-07,文具,54
2023-06-08,服装,76
2023-06-09,餐饮,120
2023-06-10,文具,30

In the Python code, we will use the pandas library to

Guess you like

Origin blog.csdn.net/weixin_43263566/article/details/131135866