Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- DataFrame
- IN
- Python
- data
- hierarchical_clustering
- pandas
- list
- elbow method
- 최댓값
- append()
- analizer
- Dictionary
- string
- DataAccess
- matplotlib
- nan
- dendrogram
- Machine Learning
- count()
- len()
- 덴드로그램
- del
- numpy
- 반복문
- 분류 결과표
- insert()
- wcss
- 최솟값
- function
- sklearn
Archives
- Today
- Total
개발공부
[Python] Pandas 데이터 정렬하기 sort_values(), sort_index() 본문
import pandas as pd
df = pd.DataFrame({'Employee ID':[111, 222, 333, 444],
'Employee Name':['Chanel', 'Steve', 'Mitch', 'Bird'],
'Salary [$/h]':[35, 29, 38, 20],
'Years of Experience':[3, 4 ,9, 1]})
df

sort_index()
인덱스에 기반하여 정렬한다.
# ascending = True면 오름차순, False면 내림차순
df.sort_index()

sort_values()
데이터에 기반하여 정렬한다.
# 경력을 오름차순으로 정렬
df.sort_values('Years of Experience')

# 경력을 내림차순으로 정렬
df.sort_values('Years of Experience', ascending = False)

#이름과 경력으로 정렬하되,
# 이름은 내림차순, 경력은 오름차순으로 정렬
# 여러개에 대해서 정렬 할 때는 리스트로 정리한다.
df.sort_values(['Employee Name', 'Years of Experience'], ascending = [False, True])

'Python > Pandas' 카테고리의 다른 글
| [Python] Pandas pivot_table() 생성하기 (0) | 2022.05.04 |
|---|---|
| [Python] Pandas Dataframe 합치기 concat(), merge() (0) | 2022.05.03 |
| [Python] Pandas Dataframe 조건을 만족하는 데이터 얻기, apply()(=함수를 이용해 얻기) (0) | 2022.05.03 |
| [Python]Pandas 카테고리컬 데이터 확인하기, 이를 묶어 처리하기 groupby() (0) | 2022.05.03 |
| [Python] Pandas Dataframe NaN 다루기 (0) | 2022.05.02 |