current position:Home>You can easily get started with Excel. Python data analysis package pandas (VI): sorting
You can easily get started with Excel. Python data analysis package pandas (VI): sorting
2021-08-22 05:22:17 【Excel catalyst】
> 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
Preface
Sorting is a very basic data operation ,Excel The sorting function in is very flexible , You can sort rows and columns . Look at this article pandas How to do with Excel Same flexibility .
Excel Sort
Excel Sorting data in is very simple . as follows :
- - Function card " data "," Sort " Button , The sort settings pop-up window appears
- - We can set the sort by field
- - First set up and press class Ascending , class If the same, press Chinese language and literature Grades are in ascending order
- - At the top right of the pop-up window , Yes " Set up " Button , You can choose to sort rows or columns
pandas Sort
pandas Sorting in is also very simple , And basically with Excel The process principle is consistent , After all, it's all data tools . as follows :
- - DataFrame.sort_values(), You can sort them
- - The first parameter specifies the sort by key column
- - The second parameter specifies the ascending and descending sequence adopted by the key column corresponding to the first parameter
- - You can also set axis=1 , Sort by row ( There are few practical application scenarios )
Excel The sorting in can be customized , That is, let users customize the order ,pandas in , This function is not placed in sort_values To realize .
> actually Excel It also puts the custom sequence in a separate function
such as , hope Class according to "5,4,2,1,3,6,7" Sort , as follows :
- - pandas You need to construct a column first Categorical , As an auxiliary column
- - Categorical The second parameter at instantiation specifies the order
- - Finally, call sort_values Method to complete custom sorting
> pandas Custom sorting in is relatively cumbersome , But we can completely encapsulate common operations by ourselves , You can also complete the custom sorting in one sentence
summary
- - DataFrame.sort_values() , Sort the data
- - The first parameter specifies the sort by key column
- - The second parameter specifies the lifting sequence
- - When a custom collation is required , It needs to be constructed Categorical Auxiliary 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-22
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.
https://en.pythonmana.com/2021/08/20210822052204138J.html
The sidebar is recommended
- [Python introduction project] use Python to generate QR code
- Compile D + +, and use d to call C from python
- Quickly build Django blog based on function calculation
- Python collects and monitors system data -- psutil
- Finally, this Python import guide has been sorted out. Look!
- Quickly build Django blog based on function calculation
- Python interface test unittest usage details
- Implementation of top-level design pattern in Python
- You can easily get started with Excel. Python data analysis package pandas (VII): breakdown
- Python simulation random coin toss (non optimized version)
guess what you like
-
Python tiktok 5000+ V, and found that everyone love this video.
-
Using linear systems in python with scipy.linalg
-
Using linear systems in python with scipy.linalg
-
Together with Python to do a license plate automatic recognition system, fun and practical!
-
You can easily get started with Excel. Python data analysis package pandas (XI): segment matching
-
Advanced practical case: Javascript confusion of Python anti crawling
-
Using linear systems in python with scipy.linalg
-
Fast power modulus Python implementation of large numbers
-
Quickly build Django blog based on function calculation
-
This paper clarifies the chaotic switching operation and elegant derivation of Python
Random recommended
- You can easily get started with Excel pandas (I): filtering function
- You can easily get started with Excel. Python data analysis package pandas (II): advanced filtering (I)
- You can easily get started with Excel. Python data analysis package pandas (2): advanced filtering (2)
- You can easily get started with Excel. Python data analysis package pandas (3): making score bar
- Test Development: self study Dubbo + Python experience summary and sharing
- You can easily get started with Excel. Python data analysis package pandas (V): duplicate value processing
- How does Python correctly call jar package encryption to get the encrypted value?
- Python 3 interview question: give an array. If there is 0 in the array, add a 0 after 0, and the overall array length remains the same
- Python simple Snake game (single player mode)
- Using linear systems in python with scipy.linalg
- Python executes functions and even code through strings! Come and understand the operation of such a top!
- Decoding the verification code of Taobao slider with Python + selenium, the road of information security
- [Python introduction project] use Python to generate QR code
- Vanessa basks in her photos and gets caught up in the golden python. There are highlights in the accompanying text. She can't forget Kobe after all
- [windows] Python installation pyteseract
- [introduction to Python project] create bar chart animation in Python
- Fundamentals of Python I
- Python series tutorials 116
- Python code reading (chapter 35): fully (deeply) expand nested lists
- Practical series 1 ️⃣ Wechat applet automatic testing practice (with Python source code)
- Python Basics: do you know how to use lists?
- Solution of no Python 3.9 installation was detected when uninstalling Python
- [Python homework] coupling network information dissemination
- [common links of Python & Python]
- Python application software development tool - tkinterdesigner v1.0 5.1 release!
- [Python development tool tkinterdiesigner]: example: develop stock monitoring alarm using Tkinter desinger
- [Python development tool Tkinter designer]: Lecture 2: introduction to Tkinter designer's example project
- [Python development tool Tkinter designer]: Lecture 1: introduction to the basic functions of Tkinter Designer
- [introduction to Python tutorial] use Python 3 to teach you how to extract any HTML main content
- Python socket implements UDP server and client
- Python socket implements TCP server and client
- leetcode 1261. Find Elements in a Contaminated Binary Tree(python)
- [algorithm learning] 1486 Array XOR operation (Java / C / C + + / Python / go / trust)
- leetcode 1974. Minimum Time to Type Word Using Special Typewriter(python)
- The mobile phone uses Python to operate picture files
- [learning notes] Python exception handling try except...
- Two methods of using pandas to read poorly structured excel. You're welcome to take them away
- Python sum (): the summation method of Python
- Practical experience sharing: use pyo3 to build your Python module
- Using Python to realize multitasking process