Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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
more
Archives
Today
Total
관리 메뉴

SERi

pandas.DataFrame.loc 본문

Pandas

pandas.DataFrame.loc

링다링 2022. 11. 24. 16:46

특정 행, 열, 행열 등 조회가능

 

# fare이 50 이상인 데이터 추출
titanic.loc[titanic["fare"] > 50]

# fare이 50 이상, place가 2인 데이터 추출
titanic.loc[(titanic["fare"] > 50) & (titanic["pclass"] == 2)]

 

# fare이 50 이상인 alive 컬럼 데이터 추출
titanic.loc[titanic["fare"] > 50, ["alive"]]

 

# 조건 2개 + 특정 컬럼만 출력
titanic.loc[(titanic["fare"] > 50) & (titanic["embarked"] == "S"), ["age"]]


많이 사용하는 방법

숙지해두자 이건제발..!

# 추출한 컬럼을 values에 대입
titanic.loc[titanic["age"] > 20, "age_2" ] = "age_20"
titanic["age_2"].value_counts()

 

'Pandas' 카테고리의 다른 글

pandas.DataFrame.sort_values  (0) 2022.11.24
pandas.DataFrame.agg  (0) 2022.11.24
pandas.DataFrame.describe  (0) 2022.11.24
pandas.DataFrame.corr  (0) 2022.10.07
Comments