# shifting the last column in the dataframe to the first place [closed]

While this question had relative answers, I couldn't find an efficient and robust way of doing it. I have to shift the last column in my data frame to the first without disturbing any of the other columns. How should I do this ? Thanks in advance.

cols = list(df.columns)
cols = [cols[-1]] + cols[:-1]
df = df[cols]

• Forgot the list. Edited
– Fred
Sep 24 '18 at 12:26
• this puts the column in the fifth place and not at the first when I ran this code snippet. Sep 24 '18 at 12:29
• That's weird. This should work for any regular data frame. I can't help you out without further details then
– Fred
Sep 24 '18 at 12:50
• Wait, let me post my notebook cloudlink. Sep 24 '18 at 12:53
• Works as expected. Mar 2 '20 at 18:59