dataframe数据的反转(reverse)

方法1:data.reindex(index=data.index[::-1])
方法2:data.iloc[::-1]
举例如下:

a=pd.DataFrame({‘gansu’:[2001,2002,2003],‘guangdong’:[2002,2005,2006],‘hunan’:[2003,2009,2010]},index=range(3))
a
gansu guangdong hunan
0 2001 2002 2003
1 2002 2005 2009
2 2003 2006 2010

a.iloc[::-1]
gansu guangdong hunan
2 2003 2006 2010
1 2002 2005 2009
0 2001 2002 2003

a.reindex(index=a.index[::-1])
gansu guangdong hunan
2 2003 2006 2010
1 2002 2005 2009
0 2001 2002 2003

你可能感兴趣的:(pandas,学习笔记)