pandas from beginner to proficient-pivot table

The collected data is usually divided into multiple files or databases after storage. How to splice these files as needed or connect them by key is very important. This section will introduce the complex operations of data indexing such as hierarchical index, stack, unstack, seet_index, reset_index, etc. to help reconstruct data, data splicing such as merge, join, concat, combine_first, etc. to help connect data, as well as the use of pivot tables.

pivot table

C.1 df.pivot

Assume that the current data is deconstructed as shown in the table below. The item column represents different keys (can be converted into many columns), and the value represents different values.
Insert image description here
Now we want to convert it into a regular Df New style, that is, each column is a kind of data using Df.pivot(index=, columns='item',value=)
as shown below:
Insert image description here

  • The effect achieved is similar to moving the item column to the column index.

Guess you like

Origin blog.csdn.net/qq_48081868/article/details/132521830