DataFrame의 값을 이용해 정렬.
sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)
A B C D
2020-01-01 0.518066 0.222793 0.631694 0.081203
2020-01-02 0.759065 0.661978 0.352200 0.208119
2020-01-03 0.779618 0.903329 0.157427 0.600756
2020-01-04 0.939167 0.418259 0.007953 0.966399
2020-01-05 0.897157 0.166408 0.645125 0.076351
위 데이터를 df_A
라고 하고, 컬럼 'C'를 이용해 내림차순 정렬을 하면
df_A.sort_values(by='C', ascending=False)
▶ 결과
A B C D
2020-01-05 0.897157 0.166408 0.645125 0.076351
2020-01-01 0.518066 0.222793 0.631694 0.081203
2020-01-02 0.759065 0.661978 0.352200 0.208119
2020-01-03 0.779618 0.903329 0.157427 0.600756
2020-01-04 0.939167 0.418259 0.007953 0.966399
DataFrame index를 이용해 정렬.
sort_index(axis=0, level=None, ascending=True, inplace=False, kind='quicksort', na_position='last', sort_remaining=True, ignore_index=False, key=None)
A B C D
2020-01-05 0.897157 0.166408 0.645125 0.076351
2020-01-01 0.518066 0.222793 0.631694 0.081203
2020-01-02 0.759065 0.661978 0.352200 0.208119
2020-01-03 0.779618 0.903329 0.157427 0.600756
2020-01-04 0.939167 0.418259 0.007953 0.966399
위 데이터를 df_A
라고 할때 index를 이용해 정렬을 하면
df_A.describe()
▶ 결과
A B C D
count 5.000000 5.000000 5.000000 5.000000
mean 0.601574 0.615313 0.342169 0.504192
std 0.322117 0.260882 0.375071 0.404038
min 0.169650 0.347747 0.008279 0.069692
25% 0.370939 0.410226 0.183893 0.170404
50% 0.698545 0.599367 0.234197 0.446965
75% 0.829877 0.720031 0.299867 0.850727
max 0.938858 0.999196 0.984611 0.983172
df_A.sort_index()
▶ 결과
A B C D
2020-01-01 0.518066 0.222793 0.631694 0.081203
2020-01-02 0.759065 0.661978 0.352200 0.208119
2020-01-03 0.779618 0.903329 0.157427 0.600756
2020-01-04 0.939167 0.418259 0.007953 0.966399
2020-01-05 0.897157 0.166408 0.645125 0.076351