采取以下数据框架:
x = np.tile(np.arange(3),3)
y = np.repeat(np.arange(3),3)
df = pd.DataFrame({"x": x, "y": y})
Run Code Online (Sandbox Code Playgroud)
x y
0 0 0
1 1 0
2 2 0
3 0 1
4 1 1
5 2 1
6 0 2
7 1 2
8 2 2
Run Code Online (Sandbox Code Playgroud)
我需要先排序x,然后排在第二位y:
df2 = df.sort(["x", "y"])Run Code Online (Sandbox Code Playgroud)
x y
0 0 0
3 0 1
6 0 2
1 1 0
4 1 1
7 1 2
2 2 0
5 2 1
8 2 2 …Run Code Online (Sandbox Code Playgroud)