current position:Home>You can easily get started with Excel. Python data analysis package pandas (3): making score bar

You can easily get started with Excel. Python data analysis package pandas (3): making score bar

2021-08-23 04:47:02 Excel catalyst

Series articles :

I often listen to others Python How powerful in the data field , As a result, I studied for a long time , Even data processing is a death of trouble . Only later , It's not Python Data processing is powerful , But he has a data analysis artifact —— pandas


Many never touched pandas After seeing the relevant information , I think this thing can't handle, like Excel Data in that complex and changeable format . Actually pandas Compared with manual operation 、 PivotTable operations are even Vba operation , It can process complex shape data more flexibly and quickly .

This time, , So let's see how it works pandas Generate various format data such as payslip at one time .

Case study

Continue to use the transcript data :

We want to list each student's transcript separately , That is, a row of records becomes a small table :

Excel skill

use Excel Can the built-in function complete this work in batch ? Certainly. , It just takes a lot of skill . But I always say , Ideas are more important than methods , This is because , If you understand this Excel The operation process , The same idea can be applied to pandas Finish in .

have a look Excel How to accomplish this requirement , We use it 10 A record to demonstrate :

  • Add auxiliary sequence , Each value is separated by 2( This is because each row of the resulting data is separated by 2 That's ok )

  • Under the auxiliary column , Generating sequences ( The end value is the mantissa of the previous sequence )
  • Use Excel The built-in generation series function can

  • Batch add header row
  • from 3 Start , every other 3 Set a title for the row

  • Remove duplicate sequence lines

  • Finally, sort according to the auxiliary column , You get the result

pandas practice

pandas There are many ways to implement , This section begins with the above Excel The solution is basically the same way . as follows :

  • Modify row index value , amount to Excel The first step

  • reindex You can give non-existent row index values , Then those lines will become empty
  • amount to Excel The second and fourth steps in

  • Last , From the index 3 Start , every other 3 Just assign row and column headings

The complete code is as follows :


The method introduced in this paper has great practical limitations , For example, it cannot be divided according to any dimension , And it requires a user pair pandas Have a deep understanding of the index in . Next time, we will introduce a general way , You can also add summary rows to each small table .

If you want to learn from scratch pandas , Then you can look at my pandas special column .

This article is from WeChat official account. - Excel catalyst (ExcelCuiHuaJi)

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the [email protected] Delete .

Original publication time : 2019-08-21

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

copyright notice
author[Excel catalyst],Please bring the original link to reprint, thank you.

Random recommended