How it works...

In this recipe, we took two lists and a Seq data structure and converted them to DataFrame and used df1.show() and df1.printSchema() to display contents and schema for the table.

DataFrames can be created from both internal and external sources. Just like SQL tables, the DataFrames have schemas associated with them that can either be inferred or explicitly defined using Scala case classes or the map() function to explicitly convert while ingesting the data.

Get Apache Spark 2.x Machine Learning Cookbook 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.