这是我的系列
Date
April 389
August 406
December 350
February 361
January 333
July 389
June 400
March 383
May 417
November 372
October 383
September 406
Name: Data_Value, dtype: int64
我想对它进行排序,以使索引成为1月,5月,3月...。 我尝试了这段代码:
df.index=pd.to_datetime(df.index, errors='coerce')
df = df.sort_index()
我得到以下输出:
Date
NaT 389
NaT 406
NaT 350
NaT 361
NaT 333
NaT 389
NaT 400
NaT 383
NaT 417
NaT 372
NaT 383
NaT 406
Name: Data_Value, dtype: int64
我该如何解决?