intro to data cleaning with apache spark
play

Intro to data cleaning with Apache Spark CLEAN IN G DATA W ITH P - PowerPoint PPT Presentation

Intro to data cleaning with Apache Spark CLEAN IN G DATA W ITH P YS PARK Mike Metzger Data Engineering Consultant What is Data Cleaning? Data Cleaning : Preparing raw data for use in data processing pipelines. Possible tasks in data


  1. Intro to data cleaning with Apache Spark CLEAN IN G DATA W ITH P YS PARK Mike Metzger Data Engineering Consultant

  2. What is Data Cleaning? Data Cleaning : Preparing raw data for use in data processing pipelines. Possible tasks in data cleaning: Reformatting or replacing text Performing calculations Removing garbage or incomplete data CLEANING DATA WITH PYSPARK

  3. Why perform data cleaning with Spark? Problems with typical data systems: Performance Organizing data �ow Advantages of Spark: Scalable Powerful framework for data handling CLEANING DATA WITH PYSPARK

  4. Data cleaning example Raw data: Cleaned data: name age (years) city last name �rst name age (months) state Smith, John 37 Dallas Smith John 444 TX Wilson, A. 59 Chicago Wilson A. 708 IL null 215 CLEANING DATA WITH PYSPARK

  5. Spark Schemas De�ne the format of a DataFrame May contain various data types: Strings, dates, integers, arrays Can �lter garbage data during import Improves read performance CLEANING DATA WITH PYSPARK

  6. Example Spark Schema Import 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) ]) Read CSV �le containing data people_df = spark.read.format('csv').load(name='rawdata.csv', schema=peopleSchema) CLEANING DATA WITH PYSPARK

  7. Let's practice! CLEAN IN G DATA W ITH P YS PARK

  8. Immutability and Lazy Processing CLEAN IN G DATA W ITH P YS PARK Mike Metzger Data Engineering Consultant

  9. Variable review Python variables: Mutable Flexibility Potential for issues with concurrency Likely adds complexity CLEANING DATA WITH PYSPARK

  10. Immutability Immutable variables are: A component of functional programming De�ned once Unable to be directly modi�ed Re-created if reassigned Able to be shared ef�ciently CLEANING DATA WITH PYSPARK

  11. Immutability Example De�ne a new data frame: voter_df = spark.read.csv('voterdata.csv') Making changes: voter_df = voter_df.withColumn('fullyear', voter_df.year + 2000) voter_df = voter_df.drop(voter_df.year) CLEANING DATA WITH PYSPARK

  12. Lazy Processing Isn't this slow? Transformations Actions Allows ef�cient planning voter_df = voter_df.withColumn('fullyear', voter_df.year + 2000) voter_df = voter_df.drop(voter_df.year) voter_df.count() CLEANING DATA WITH PYSPARK

  13. Let's practice! CLEAN IN G DATA W ITH P YS PARK

  14. Understanding Parquet CLEAN IN G DATA W ITH P YS PARK Mike Metzger Data Engineering Consultant

  15. Dif�culties with CSV �les No de�ned schema Nested data requires special handling Encoding format limited CLEANING DATA WITH PYSPARK

  16. Spark and CSV �les Slow to parse Files cannot be �ltered (no "predicate pushdown") Any intermediate use requires rede�ning schema CLEANING DATA WITH PYSPARK

  17. The Parquet Format A columnar data format Supported in Spark and other data processing frameworks Supports predicate pushdown Automatically stores schema information CLEANING DATA WITH PYSPARK

  18. Working with Parquet Reading Parquet �les df = spark.read.format('parquet').load('filename.parquet') df = spark.read.parquet('filename.parquet') Writing Parquet �les df.write.format('parquet').save('filename.parquet') df.write.parquet('filename.parquet') CLEANING DATA WITH PYSPARK

  19. Parquet and SQL Parquet as backing stores for SparkSQL operations flight_df = spark.read.parquet('flights.parquet') flight_df.createOrReplaceTempView('flights') short_flights_df = spark.sql('SELECT * FROM flights WHERE flightduration < 100') CLEANING DATA WITH PYSPARK

  20. Let's Practice! CLEAN IN G DATA W ITH P YS PARK

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend