Sometimes, we want the “Target” column to be the last one in the Data Frame. Let’s see how we can do it in Pandas. Assume that we have the following data frame:
import pandas as pd df = pd.DataFrame({'A':[1,2,3], 'Target':[0,1,0], 'B':[4,5,6]}) df
Now, we can reindex the columns as follows:
df = df.reindex(columns = [col for col in df.columns if col != 'Target'] + ['Target']) df