Data Analysis: How to Easily Conduct Baseline Comparative Analysis

The need for baseline analysis

In our daily work, we often encounter the need for baseline comparison analysis, such as comparison with last year's sales and comparison with average sales over the past years.

First, we can use the computing power of the platform to calculate the sales data of each month over the years, as shown in the figure below.

Use pivot_table for pivot conversion

After getting the statistical data in chronological order, we use pivot_table to pivot the long table into a wide table by year.

The first parameter of pivot_table is the original table name, the second parameter is the converted x-axis, and the third parameter is the parameter that needs to be converted. Here is the benchmark 'year' for data comparison. The fourth parameter is the numerical column name that needs to be compared, here it is 'cumulative sales'.

The following is the data form after perspective conversion.

This data format can directly display data comparisons over the years in chart form.

If you need to compare it with the average of previous years, or perform more complex processing, you can further process it in the query as follows.

Guess you like

Origin blog.csdn.net/Yhpdata888/article/details/131559470