how to sort only some of the columns in a data frame in pandas?
问题 Is there a way to sort only some elements of a list in a user-defined manner? import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(5, 6), columns=['x','a','c','y','b','z']) I'd like to sort the columns of df in a way that the first 3 columns are [x, y, z] (in this order), and it doesn't matter where the remaining columns are placed. For this example I could do it manually, but as the list gets bigger it would be convenient to use a more appropriate method. I thought of