按升序对pandas DataMatrix进行排序

Jas*_*pel 2 python sorting numpy pandas

pandas DataFrame对象有一个sort方法,但pandas DataMatrix对象没有.

按索引(日期列)按升序对此DataMatrix对象进行排序的最佳方法是什么?

>>> dm
               compound_ret
2/16/2011 0:00  0.006275682
2/15/2011 0:00  0.003098208
2/14/2011 0:00  0.0055039
2/13/2011 0:00  0.011471506
2/12/2011 0:00  0.011853712
2/11/2011 0:00  0.009558739
2/10/2011 0:00  0.014127912
2/9/2011 0:00   0.02042923
2/8/2011 0:00   0.023308062
Run Code Online (Sandbox Code Playgroud)

结果应该是DataMatrix,其中第一个条目为2/8/2011,最后一个条目为2/16/2011.compound_ret列中的条目应遵循排序中的日期.所以结果应该是这样的:

>>>dm_sorted
                  compound_ret
2/8/2011 0:00    0.023308062
2/9/2011 0:00    0.02042923
2/10/2011 0:00  0.014127912
2/11/2011 0:00  0.009558739
2/12/2011 0:00  0.011853712
2/13/2011 0:00  0.011471506
2/14/2011 0:00  0.0055039
2/15/2011 0:00  0.003098208
2/16/2011 0:00  0.006275682
Run Code Online (Sandbox Code Playgroud)

Wes*_*ney 8

事实上0.2和0.3之间的I重命名sortUp/ sortDown到单sort方法.对于那个很抱歉.

如果可以,我绝对建议你继续保持熊猫的前沿(https://github.com/wesm/pandas)!另外,考虑将IPython用于所有交互式工作(http://ipython.scipy.org) - 我发现对象的完成和对象的简单内省有助于查找方法和探索文档字符串.