I'm looking for a simple way to sort a pandas dataframe by the absolute value of a particular column, but without actually changing the values within the dataframe. Something similar to sorted(df, key=abs)
. So if I had a dataframe like:
a b
0 1 -3
1 2 5
2 3 -1
3 4 2
4 5 -9
The resultant sorted data when sorting on 'b' would look like:
a b
2 3 -1
3 4 2
0 1 -3
1 2 5
4 5 -9
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…