Update index after sorting data-frame

后端 未结 4 721
一向
一向 2020-12-12 15:44

Take the following data-frame:

x = np.tile(np.arange(3),3)
y = np.repeat(np.arange(3),3)
df = pd.DataFrame({\"x\": x, \"y\": y})
           


        
4条回答
  •  庸人自扰
    2020-12-12 15:48

    You can set new indices by using set_index:

    df2.set_index(np.arange(len(df2.index)))
    

    Output:

       x  y
    0  0  0
    1  0  1
    2  0  2
    3  1  0
    4  1  1
    5  1  2
    6  2  0
    7  2  1
    8  2  2
    

提交回复
热议问题