การทำความสะอาดข้อมูลด้วย PySpark
Mike Metzger
Data Engineering Consultant
การทำความสะอาดข้อมูล: การเตรียมข้อมูลดิบให้พร้อมใช้งานใน data processing pipeline
งานที่พบในการทำความสะอาดข้อมูล:
ปัญหาของระบบข้อมูลทั่วไป:
ข้อดีของ 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 |
นำเข้า schema
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