python 3.x - sorting a dataframe by index -
i have dataframe called df indexed date trying sort oldest date newest.
i have tried use both:
df = df.sort(axis=1)
and
df = df.sort_index(axis=1)
but can see date order in following df tail dates have not been sorted date order.
wood_density date 2016-01-27 5.8821 2016-01-28 5.7760 2015-12-25 nan 2016-01-01 nan 2015-12-26 nan
could offer assistance please?
many thanks
use sort_index
sort index:
in [19]: df = df.sort_index() df out[19]: wood_density date 2015-12-25 nan 2015-12-26 nan 2016-01-01 nan 2016-01-27 5.8821 2016-01-28 5.7760
sort
, deprecated sort_values
or sort_index
sorts on row labels default axis=0
would've worked if didn't pass this:
in [21]: df.sort() out[21]: wood_density date 2015-12-25 nan 2015-12-26 nan 2016-01-01 nan 2016-01-27 5.8821 2016-01-28 5.7760
Comments
Post a Comment