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 でデータをクレンジングする