arr = df['A'].values ## convert the column to NumPy array arr_sorted = np.sort(df['A']) ## sort the NumPy array # Create a new DataFrame using the sorted array df_np_sorted = pd.DataFrame({'A': arr_sorted, 'B': df.B.values[np.argsort(arr)]}) ## arrange column B in the correct order ## Total run-time: 32.1 s
Hosted onDeepnote