Creating a DataFrame from Scala case classes

In this recipe, we'll see how to create a new DataFrame from Scala case classes.

How to do it...

  1. We create a new entity called Employee with the id and name fields, like this:
    case class Employee(id:Int, name:String)
    

    Similar to the previous recipe, we create SparkContext and SQLContext.

    val conf = new SparkConf().setAppName("colRowDataFrame").setMaster("local[2]")
    
    //Initialize Spark context with Spark configuration.  This is the core entry point to do anything with Spark
    val sc = new SparkContext(conf) ...

Get Scala: Guide for Data Science Professionals now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.