[Python] Sort a pandas DataMatrix in ascending order

Discussão em 'Python' iniciado por Stack, Maio 3, 2025.

  1. Stack

    Stack Membro Participativo

    The pandas DataFrame object has a sort method but pandas DataMatrix object does not.

    What is the best way to sort this DataMatrix object by index (the date column) in ascending order?

    >>> 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


    The result should be the DataMatrix with 2/8/2011 as the first entry and 2/16/2011 as the last entry. The entries in the compound_ret column should follow their date in the sort. So the result should look something like this:

    >>>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

    Continue reading...

Compartilhe esta Página