O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Filling in bad or missing data

Let's take a looks at the year of movie review and clean it up.

We have already seen an example of filtering out bad data. Following on from the preceding code, the following code snippet applies the fill-in approach to the bad release date record by assigning a value which is Empty String as 1900 (this will be later replaced by the Median):

Util.spark.udf.register("convertYear", Util.convertYear _) movie_data_df.show(false) val movie_years = Util.spark.sql("select convertYear(date) as year from   movie_data") movie_years.createOrReplaceTempView("movie_years") Util.spark.udf.register("replaceEmptyStr", replaceEmptyStr _) val years_replaced =  Util.spark.sql("select replaceEmptyStr(year)  as r_year from movie_years") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required