본문 바로가기
Tech/Python

pandas - Sorting DataFrame

by Jyubaeng2 2023. 7. 30.

Data Import

import pandas as pd
from sklearn.datasets import load_boston

# Load the Boston Housing Prices dataset
boston = load_boston()
boston_df = pd.DataFrame(boston.data, columns=boston.feature_names)
boston_df['PRICE'] = boston.target

Sorting DataFrame

Sorting can be done using .sort_values(). We need to sepcify the columns in a list and also specify if we want to sort in ascending or descending order for the columns. pandas has a better way to sort the dataframe, so I will just briefly explain .sort_values() here.

 

boston_df.sort_values(['CRIM', 'TAX'], ascending=[True, False])

그다 필요없는 기술이지만 일단 알아두면 좋을듯...?

 

https://ai-fin-tech.tistory.com/entry/Subsetting-Columns-and-Rows-with-pandas

 

Subsetting Columns and Rows with pandas

Data Import import pandas as pd from sklearn.datasets import load_boston # Load the Boston Housing Prices dataset boston = load_boston() boston_df = pd.DataFrame(boston.data, columns=boston.feature_names) boston_df['PRICE'] = boston.target Subsetting a sin

ai-fin-tech.tistory.com

 

'Tech > Python' 카테고리의 다른 글

pandas - Complete Usage of loc and iloc  (1) 2023.07.30
pandas - Subsetting Columns and Rows  (1) 2023.07.30
pandas - Basic DataFrame Inspection  (1) 2023.07.30
pandas - Data Import  (1) 2023.07.30
기계 학습을 위한 무료 데이터셋 Top 3  (2) 2023.07.30

댓글