시작하기무료로 시작하기

값 그룹화 및 재코딩

evanston311.category에는 약 150개에 달하는 고유값이 있습니다. 그런데 이 중 일부는 "Main Category - Details" 형식을 따릅니다. main category 기준으로 집계하면 어떤 요청이 많은지 더 명확하게 파악할 수 있습니다.

이를 위해 임시 테이블 recode를 생성하여 category의 고유값을 새로운 standardized 값으로 매핑합니다. standardized 값은 대시('-') 앞에 해당하는 category 부분으로 설정합니다. 이 값은 split_part() 함수로 추출합니다.

split_part(string text, delimiter text, field int)

또한 이 패턴에 맞지 않는 일부 항목은 추가적으로 정리가 필요합니다.

그런 다음 evanston311 테이블을 recode와 조인하여 새로운 standardized 범주 값으로 요청을 그룹화합니다.

이 연습은 강의의 일부입니다

SQL을 활용한 탐색적 데이터 분석

강의 보기

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

-- Fill in the command below with the name of the temp table
DROP TABLE IF EXISTS ___;

-- Create and name the temporary table
CREATE ___ ___ ___ AS
-- Write the select query to generate the table with distinct values of category and standardized values
  SELECT DISTINCT category, 
         ___(___(___, ___, ___)) AS standardized
    -- What table are you selecting the above values from?
    FROM ___;
    
-- Look at a few values before the next step
SELECT DISTINCT standardized 
  FROM recode
 WHERE standardized LIKE 'Trash%Cart'
    OR standardized LIKE 'Snow%Removal%';
코드 편집 및 실행