Pandas学习笔记,DataFrame的排序问题

数据来源见前边的几篇随笔

对其中的一列排序

data.high.sort_values(ascending=False)
data.high.sort_values(ascending=True)
data['high'].sort_values(ascending=False)
data['high'].sort_values(ascending=True)
p = data.high.sort_values()
print(p)
date
2015-01-05    11.39
2015-01-06    11.66
2015-01-09    11.71
2015-01-08    11.92
2015-01-07    11.99
Name: high, dtype: float64

可以看到返回的是一个Series

我们也可以对整个DataFrame进行排序

t = data.sort_values(['high', 'low'],ascending=True)
print(t)

优先按high排序,high有相同的,按lower排序

             open   high  close    low    volume  price_change  p_change  
date                                                                       
2015-01-05  11.16  11.39  11.26  10.89  46383.57          0.14      1.26   
2015-01-06  11.13  11.66  11.61  11.03  59199.93          0.35      3.11   
2015-01-09  11.68  11.71  11.23  11.19  44851.56         -0.44     -3.77   
2015-01-08  11.70  11.92  11.67  11.64  56845.71         -0.25     -2.10   
2015-01-07  11.58  11.99  11.92  11.48  86681.38          0.31      2.67   

               ma5    ma10    ma20     v_ma5    v_ma10     v_ma20  turnover  
date                                                                         
2015-01-05  11.156  11.212  11.370  58648.75  68429.87  100765.24      1.59  
2015-01-06  11.182  11.155  11.382  54854.38  63401.05   98686.98      2.03  
2015-01-09  11.538  11.363  11.682  58792.43  60665.93  107924.27      1.54  
2015-01-08  11.516  11.349  11.647  57268.99  61376.00  105823.50      1.95  
2015-01-07  11.366  11.251  11.543  55049.74  61628.07  103010.58      2.97  
原文地址:https://www.cnblogs.com/imageSet/p/7481851.html