PySpark로 데이터 정제하기
Mike Metzger
Data Engineering Consultant
데이터 정제: 데이터 처리 파이프라인에 사용할 수 있도록 원시 데이터를 준비합니다.
데이터 정제에서 할 수 있는 작업:
일반적 데이터 시스템의 문제:
Spark의 강점:
원시 데이터:
| name | age (years) | city |
|---|---|---|
| Smith, John | 37 | Dallas |
| Wilson, A. | 59 | Chicago |
| null | 215 |
정제된 데이터:
| last name | first name | age (months) | state |
|---|---|---|---|
| Smith | John | 444 | TX |
| Wilson | A. | 708 | IL |
스키마 가져오기
import pyspark.sql.types
peopleSchema = StructType([
# Define the name field
StructField('name', StringType(), True),
# Add the age field
StructField('age', IntegerType(), True),
# Add the city field
StructField('city', StringType(), True)
])
데이터가 담긴 CSV 읽기
people_df = spark.read.format('csv').load(name='rawdata.csv', schema=peopleSchema)
PySpark로 데이터 정제하기