강의

멘토링

커뮤니티

Inflearn Community Q&A

veryycherry4138's profile image
veryycherry4138

asked

Getting started with Python data analysis using public data

[12/21] Creating a text preprocessing function using regular expressions

"공원보유시설(운동시설)"의 unique 값

Written on

·

215

1

안녕하세요 선생님

df["공원보유시설(운동시설)"].value_counts().index.tolist()
df["공원보유시설(운동시설)"].unique().tolist()

위의 두 코드가 결과가 다른지 궁금합니다.

value_counts()는 고유값의 개수를 세주기 때문에 index만 취하면 동일하지 않을까요...?

pandaspythonnumpy

Answer 2

0

veryycherry님의 프로필 이미지
veryycherry
Questioner

아.. 그런데 왜 길이도 다른 걸까요...?

value_counts는 고유값과 그 개수를 알려주고

unique는 고유값을 알려주는 함수로 이해했는데 아닌가요?

todaycode님의 프로필 이미지
todaycode
Instructor

안녕하세요.

value_counts() 는 결측치를 제외하고 구합니다. unique() 로 구한 값에는 결측치도 유일값으로 찾습니다. 

그래서 gym1 에는 결측치를 의미하는 값이 없지만 gym2 에는 결측치를 의하는 nan 값이 있습니다.

veryycherry님의 프로필 이미지
veryycherry
Questioner

아! 이제 완전 이해했습니다 정말 감사합니다

todaycode님의 프로필 이미지
todaycode
Instructor

감사합니다 :)

0

todaycode님의 프로필 이미지
todaycode
Instructor

안녕하세요.

value_counts() 는 빈도수를 세어주기 때문에 빈도수 순으로 인덱스 값이 정렬이 되어 아래 코드와 출력되는 리스트 안의 값의 정렬이 다르게 나옵니다.

veryycherry4138's profile image
veryycherry4138

asked

Ask a question