1# setting up a dummy dataframe
2raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
3 'age': [20, 19, 22, 21],
4 'favorite_color': ['blue', 'red', 'yellow', "green"],
5 'grade': [88, 92, 95, 70]}
6df = pd.DataFrame(raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'])
7df
8
9#now 'age' will appear at the end of our df
10df = df[['favorite_color','grade','name','age']]
11df.head()
1cols = df.columns.tolist()
2# Rearrange the list any way you want
3cols = cols[-1:] + cols[:-1]
4df = df[cols]