Swapping rows within the same pandas dataframe

后端 未结 3 489
清歌不尽
清歌不尽 2021-01-17 20:55

I\'m trying to swap the rows within the same DataFrame in pandas.

I\'ve tried running

a = pd.DataFrame(data = [[1,2],[3,4]], index=range(2), columns          


        
3条回答
  •  有刺的猬
    2021-01-17 21:50

    The accepted answer does not make changes the index name.

    If you only want to alter the order of rows you should use dataframe.reindex(arraylike). Notice that the index has changed.

提交回复
热议问题