ComenzarEmpieza gratis

Agrupar y recodificar valores

Hay casi 150 valores distintos de evanston311.category. Pero algunas de estas categorías son similares, con la forma "Categoría principal - Detalles". Podemos hacernos una mejor idea de qué solicitudes son comunes si agregamos por categoría principal.

Para ello, crea una tabla temporal recode que asigne valores distintos de category a valores nuevos de standardized. Haz que los valores de standardized sean la parte de la categoría anterior a un guión ('-'). Extrae este valor con la función split_part():

split_part(string text, delimiter text, field int)

También tendrás que hacer alguna limpieza adicional de algunos casos que no se ajustan a este patrón.

A continuación, la tabla evanston311 puede unirse a recode para agrupar las solicitudes por los nuevos valores de categoría standardized.

Este ejercicio forma parte del curso

Análisis exploratorio de datos en SQL

Ver curso

Ejercicio interactivo práctico

Pruebe este ejercicio completando este código de muestra.

-- 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%';
Editar y ejecutar código