Book Image

Big Data Analysis with Python

By : Ivan Marin, Ankit Shukla, Sarang VK
Book Image

Big Data Analysis with Python

By: Ivan Marin, Ankit Shukla, Sarang VK

Overview of this book

Processing big data in real time is challenging due to scalability, information inconsistency, and fault tolerance. Big Data Analysis with Python teaches you how to use tools that can control this data avalanche for you. With this book, you'll learn practical techniques to aggregate data into useful dimensions for posterior analysis, extract statistical measurements, and transform datasets into features for other systems. The book begins with an introduction to data manipulation in Python using pandas. You'll then get familiar with statistical analysis and plotting techniques. With multiple hands-on activities in store, you'll be able to analyze data that is distributed on several computers by using Dask. As you progress, you'll study how to aggregate data for plots when the entire data cannot be accommodated in memory. You'll also explore Hadoop (HDFS and YARN), which will help you tackle larger datasets. The book also covers Spark and explains how it interacts with other tools. By the end of this book, you'll be able to bootstrap your own Python environment, process large files, and manipulate data to generate statistics, metrics, and graphs.
Table of Contents (11 chapters)
Big Data Analysis with Python
Preface

Setting up the Jupyter Notebook


The following steps are required before getting started with the exercises:

  1. Import all the required modules and packages in the Jupyter notebook:

    import findspark
    findspark.init()
    import pyspark
    import random
  2. Now, use the following command to set up SparkContext:

    from pyspark import SparkContext
    sc = SparkContext()
  3. Similarly, use the following command to set up SQLContext in the Jupyter notebook:

    from pyspark.sql import SQLContext
    sqlc = SQLContext(sc)

    Note

    Make sure you have the PySpark CSV reader package from the Databricks website (https://databricks.com/) installed and ready before executing the next command. If not, then download it using the following command:

    pyspark –packages com.databricks:spark-csv_2.10:1.4.0

  4. Read the Iris dataset from the CSV file into a Spark DataFrame:

    df = sqlc.read.format('com.databricks.spark.csv').options(header = 'true', inferschema = 'true').load('/Users/iris.csv')

    The output of the preceding command is as follows:

    df.show(5)

    Figure 5...