Data visualization study notes: Python realizes the rectangular tree diagram of automobile brand sales

introduction

        This article will show you how to create a treemap of car brand sales using Python and the Pyecharts library. We will use Pandas to read the CSV file data, then process the data, wrap it, and finally visualize the data as a rectangular tree diagram.

Preparation

First, we need to install the relevant libraries:

  • Pandas
  • Pyecharts

It can be installed using pipthe command :

pip install pandas pyecharts

At the same time, we also need a CSV data for subsequent data processing and visualization. Here is an example data car_sales.csvthat contains information on different makes, models, and sales:

brand,model,sales
Toyota,Corolla,120000
Toyota,Camry,100000
Honda,Civic,80000
Honda,Accord,105000
Ford,Fusion,55000
Ford,F-150,105000
Chevrolet,Cruze,50000
Chevrolet,Equinox,75000
Nissan,Altima,90000
Nissan,Maxima,55000
BMW,3 Series,40000
BMW,5 Series,20000
Mercedes-Benz,C-Class,70000
Mercedes-Benz,E-Class,40000

Data Processing and Visualization

Next, let's see how we can process this data and visualize it as a treemap.

First, we use Pandas to read the CSV file and get a DataFrame object:

Guess you like

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