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})
Since pandas 1.0.0 df.sort_values has a new parameter ignore_index which does exactly what you need:
ignore_index
In [1]: df2 = df.sort_values(by=['x','y'],ignore_index=True) In [2]: df2 Out[2]: 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