Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Big Data Analytics with Hadoop 3

You're reading from  Big Data Analytics with Hadoop 3

Product type Book
Published in May 2018
Publisher Packt
ISBN-13 9781788628846
Pages 482 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Sridhar Alla Sridhar Alla
Profile icon Sridhar Alla

Table of Contents (18) Chapters

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Introduction to Hadoop Overview of Big Data Analytics Big Data Processing with MapReduce Scientific Computing and Big Data Analysis with Python and Hadoop Statistical Big Data Computing with R and Hadoop Batch Analytics with Apache Spark Real-Time Analytics with Apache Spark Batch Analytics with Apache Flink Stream Processing with Apache Flink Visualizing Big Data Introduction to Cloud Computing Using Amazon Web Services Index

DataFrame APIs and the SQL API


A DataFrame can be created in several ways; some of them are as follows:

  • Execute SQL queries, load external data such as Parquet, JSON, CSV, Text, Hive, JDBC, and so on
  • Convert RDDs to DataFrames
  • Load a CSV file

We will take a look at statesPopulation.csv here, which we will then load as a DataFrame.

The CSV has the following format of the population of US states from the years 2010 to 2016:

State

Year

Population

Alabama

2010

47,85,492

Alaska

2010

714,031

Arizona

2010

64,08,312

Arkansas

2010

2,921,995

California

2010

37,332,685

Since this CSV has a header, we can use it to quickly load into a DataFrame with an implicit schema detection:

scala> val statesDF = spark.read.option("header",
"true").option("inferschema", "true").option("sep",
",").csv("statesPopulation.csv")
statesDF: org.apache.spark.sql.DataFrame = [State: string, Year: int ... 1
more field]

Once we load the DataFrame, it can be examined for the schema:

scala> statesDF.printSchema
root
|-- State: string (nullable ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}