+1 vote
in Programming Languages by (77.2k points)
Suppose 'A' is a column in a dataframe. I want to put this column as the last column in the dataframe. How can I do it?

1 Answer

+1 vote
by (72.7k points)
selected by
 
Best answer

Suppose 'df' is the dataframe. Then you can use the following code to put the column 'A' as the last column.

cols = [col for col in df.columns if col != 'A'] 

df = df[cols + ['A']]


...