当前位置:网站首页>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])
边栏推荐
- Box model
- [TP5 online export picture generation excel detailed explanation example]
- Chapter 2 of machine learning [series] logistic regression model
- Verilog realizes binocular camera image data acquisition and Modelsim simulation, and finally matlab performs image display
- Sentinel annotation support - @sentinelresource usage details
- Installing MySQL for Linux
- Print sparse arrays and restore
- Chapter 4 of machine learning [series] naive Bayesian model
- Goodbye 2021 Hello 2022
- Servlet
猜你喜欢

A piece of code has been refactored six times by the boss, and my mind is broken

Detailed steps for installing mysql-5.6.16 64 bit green version

jenkins-凭证管理

The classification effect of converting video classification data set to picture classification data set on vgg16

Simple understanding of pseudo elements before and after

FPGA interview topic notes (I) - FPGA development process, metastable state and competitive risk, build and hold time, asynchronous FIFO depth, etc

What is a planning BOM?

Servlet

Vulhub 8.1-backdoor vulnerability recurrence

autojs,读取一行删除一行,停止自己外的脚本
随机推荐
通过R语言且只用基础package来制作一个小游戏
Build the first power cloud platform
C language war "minesweeping"
Sqoop installation tutorial
Quantitative understanding (Quantitative deep revolutionary networks for effective information: a whitepaper)
Nlp-d46-nlp match D15
Detailed steps for installing mysql-5.6.16 64 bit green version
Autojs, read one line, delete one line, and stop scripts other than your own
Simple knapsack problem
修复鼠标右键没有vscode快捷入口的问题
箭头函数的this指向
FPGA面试题目笔记(四)—— 序列检测器、跨时钟域中的格雷码、乒乓操作、降低静动态损耗、定点化无损误差、恢复时间和移除时间
Don't be afraid of xxE vulnerabilities: understand their ferocity and detection methods
Why is it that the live video of the devices connected to easygbs suddenly cannot be played? Insufficient database read / write
CCS method of installing compiler
FPGA设计——乒乓操作实现与modelsim仿真
Servlet
A multi classification model suitable for discrete value classification -- softmax regression
LeetCodeT526
Learn C language well from keywords