I have a data frame with the following data:
month
April 4484.900000
August 5664.419355
December 3403.806452
February 2655.298246
January 2176.338710
July 5563.677419
June 5772.366667
March 3692.258065
May 5349.774194
November 4247.183333
October 5199.225806
September 5766.516667
I want the data to be ordered from January to December, not alphabetically. Is there a way to reorder this?
>Solution :
You can reindex it based on the month_name :
from calendar import month_name
out = s.reindex(month_name[1:]) # with `s` your Series
Output :
print(out)
month
January 2176.338710
February 2655.298246
March 3692.258065
April 4484.900000
May 5349.774194
June 5772.366667
July 5563.677419
August 5664.419355
September 5766.516667
October 5199.225806
November 4247.183333
December 3403.806452
dtype: float64
Used input :
s = pd.read_clipboard().squeeze().rename(None).rename_axis("month")