SERi
pandas.DataFrame.loc 본문
특정 행, 열, 행열 등 조회가능
# 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