무작위 추출

Python으로 설문 데이터 분석하기

EbunOluwa Andrew

Data Scientist

설문 데이터 분석의 표본추출

  • 표본추출 = 큰 모집단에서 작은 집합
    • 더 큰 모집단을 추론
    • 표본추출 -> 데이터를 다루기 쉽게
    • 표본추출 -> 표본오차 발생
    • 큰 표본으로 오차 최소화

Unsplash의 Patrick Fore 사진 - 사탕을 든 아이

Python으로 설문 데이터 분석하기

무작위 추출

  • 각 구성원은 동일한 선택 확률
  • 편향 감소
  • 높은 내적 타당도
  • 높은 외적 타당도

복권 티켓

Python으로 설문 데이터 분석하기

.sample() 메서드

  • DataFrame.sample(n = _None_, frac = _None_, random_state = _None_)
  • n = 추출할 항목 수
  • frac = 반환할 비율(0~1)
  • random_state = 재현을 위한 시드 값
Python으로 설문 데이터 분석하기

무작위 추출 예시

import pandas as pd
survey = pd.read_csv('ABC_survey.csv')

sample = survey.sample(n=100) print(sample)
|       | employee_id | gender | onsite_work |
|-------|-------------|--------|-------------|
| 3244  | fffe330     | Female | Yes         |
| 21339 | fffe310     | Male   | Yes         |
| 1122  | fffe390     | Male   | Yes         |
| 4363  | fffe313     | Female | Yes         |
Python으로 설문 데이터 분석하기

무작위 추출 예시

import pandas as pd
survey = pd.read_csv('ABC_survey.csv')

sample = survey.sample(frac = 0.1) print(sample)
|     | employee_id | gender | onsite_work |
|-----|-------------|--------|-------------|
| 142 | fffe800     | Female | Yes         |
| 710 | fffe900     | Female | Yes         |
| 242 | fffe700     | Female | Yes         |
| 114 | fffe600     | Female | Yes         |
Python으로 설문 데이터 분석하기

무작위 추출 예시

import pandas as pd
survey = pd.read_csv('ABC_survey.csv')

sample = survey.sample( n = 100, random_state = 123)
import pandas as pd
survey = pd.read_csv('ABC_survey.csv')

sample = survey.sample( frac = 0.1, random_state = 123)
|       | employee_id | gender | onsite_work |
|-------|-------------|--------|-------------|
| 21383 | fffe3       | Female | Yes         |
| 82    | fffe0       | Male   | Yes         |
| 20739 | fffe2       | Male   | Yes         |
| 7662  | fffe9       | Female | Yes         |
|       | employee_id | gender | onsite_work |
|-------|-------------|--------|-------------|
| 21383 | fffe3       | Female | Yes         |
| 82    | fffe0       | Male   | Yes         |
| 20739 | fffe2       | Male   | Yes         |
| 7662  | fffe9       | Female | Yes         |
Python으로 설문 데이터 분석하기

Vamos praticar!

Python으로 설문 데이터 분석하기

Preparing Video For Download...