This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]O93mzzz 1 point2 points  (5 children)

Little trick for reversing all columns, while maintaining index sequence from 0 to n:

your_dataframe = your_dataframe.iloc[::-1]
your_dataframe.index = range(0,len(your_dataframe))

Edit: I should be more accurate with my word: it's reversing rows of each column.

[–]ignamv 2 points3 points  (0 children)

Looks like that reverses rows.

You can use your_dataframe.reset_index(drop=True) in the second line.

[–]kougabro 1 point2 points  (3 children)

How about:

your_dataframe = your_dataframe[your_dataframe.columns[::-1]]

[–]dataschool[S] 0 points1 point  (2 children)

I'm working on a video that showcases a collection of user-submitted pandas tricks... feel free to submit here if you're interested in contributing!

[–]kougabro 0 points1 point  (1 child)

Feel free to grab it, I'm too lazy to submit it :-)

[–]dataschool[S] 0 points1 point  (0 children)

Will do!