Note
Pandas (57) 본문
728x90
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
'Pandas' 카테고리의 다른 글
Pandas (56) (0) | 2022.10.18 |
---|---|
Pandas (55) (0) | 2022.10.14 |
Pandas (54) (0) | 2022.10.13 |
Pandas (52) (1) | 2022.09.21 |
Pandas (53) (0) | 2022.09.20 |
Comments