我有一个包含以下数据的数据框:
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
我希望数据按一月到十二月的顺序排列,而不是按字母顺序排列。有没有办法重新排序?
reindex
month_name
:
from calendar import month_name
out = s.reindex(month_name[1:]) # with `s` your Series
输出:
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