【发布时间】:2011-07-30 08:08:24
【问题描述】:
pandas DataFrame 对象有一个sort method,但 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
结果应该是 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
【问题讨论】:
标签: python sorting numpy pandas