Pandas
Pandas (57)
Jun's N
2022. 10. 19. 22:17
How to reverse the rows of a dataframe?
# Input
df = pd.DataFrame(np.arange(25).reshape(5, -1))
# 1
df.iloc[::-1, :]
# 2
print(df.loc[df.index[::-1], :])
# output
0 1 2 3 4
4 20 21 22 23 24
3 15 16 17 18 19
2 10 11 12 13 14
1 5 6 7 8 9
0 0 1 2 3 4
728x90