当前位置:网站首页>How to arrange the dataframe from small to large according to the absolute value of a column?
How to arrange the dataframe from small to large according to the absolute value of a column?
2022-06-11 06:21:00 【Geek student】
For example, according to ‘a’ The absolute values of the columns are sorted from small to large
df.iloc[df['a'].abs().argsort()]
In absolute order from big to small
df.iloc[df['a'].abs().argsort()[::-1]]
First step : So let's define one array data
import numpy as np
x=np.array([2,4,5,3,-10,1])
The second step : Output results :
y=np.argsort(x)
print(y)
The output is :y=[4 5 0 3 1 2]
The third step : summary :
argsort() The function is to x The elements in are arranged from small to large , Extract the corresponding index( Reference no. )
for example :x[4]=-10 Minimum , therefore y[0]=4,
Empathy :x[2]=5 Maximum , therefore y[5]=2.
See the following official cases :
One dimensional array: One dimensional array
>>> x = np.array([3, 1, 2])
>>> np.argsort(x)
array([1, 2, 0])
Two-dimensional array: Two dimensional array
>>> x = np.array([[0, 3], [2, 2]])
>>> x
array([[0, 3],
[2, 2]])
>>> np.argsort(x, axis=0) # Sort by column
array([[0, 1],
[1, 0]])
>>> np.argsort(x, axis=1) # Sort by row
array([[0, 1],
[0, 1]])
>>> x = np.array([3, 1, 2])
>>> np.argsort(x) # In ascending order
array([1, 2, 0])
>>> np.argsort(-x) # Sort in descending order
array([0, 2, 1])
边栏推荐
- Can Amazon, express, lazada and shrimp skin platforms use the 911+vm environment to carry out production number, maintenance number, supplement order and other operations?
- 021-MongoDB数据库从入门到放弃
- Analyze the capacity expansion mechanism of ArrayList
- The artistic director and production designer of Disney's Mandalorian revealed the virtual scene production behind it
- JIRA software annual summary: release of 12 important functions
- Servlet
- 修复鼠标右键没有vscode快捷入口的问题
- Record the first data preprocessing process
- Completabilefuture asynchronous task choreography usage and explanation
- Chapter 4 of machine learning [series] naive Bayesian model
猜你喜欢

Shandong University machine learning experiment 7 pca+ SVM face recognition

JIRA software annual summary: release of 12 important functions

Error reporting injection of SQL injection

jenkins-不同风格的项目构建

Convert multiple pictures into one NPY file storage

Compliance management 101: processes, planning and challenges

MATLAB realizes mean filtering and FPGA for comparison, and uses Modelsim waveform simulation

Analyze the principle of configuration center from the perspective of Nacos client

jenkins-凭证管理

FPGA设计中提高工作频率及降低功耗题目合集
随机推荐
Sqli-libs range 23-24 filtration and secondary injection practice
FPGA Design -- ping pong operation implementation and Modelsim simulation
What is a planning BOM?
Analyze the principle of configuration center from the perspective of Nacos client
Instanceof and type conversion
Wechat applet (authorized login) (not recommended, click the home page to view the updated authorized login)
FPGA设计中提高工作频率及降低功耗题目合集
Examinelistactivity of Shandong University project training
Markdown + typora + picgo experimental report template attached
Can Amazon, express, lazada and shrimp skin platforms use the 911+vm environment to carry out production number, maintenance number, supplement order and other operations?
Chapter 2 of machine learning [series] logistic regression model
LeetCodeT526
URL in flask_ for
021-MongoDB数据库从入门到放弃
Super details to teach you how to use Jenkins to realize automatic jar package deployment
Human gene editing technology and ethical issues behind it [personal view, for reference only]
Fix the problem that the right mouse button does not have a vscode shortcut
Jenkins voucher management
Servlet
Box model