Built with Tutify.io

    AIStudyLabs

    DataFrame - Actions

    DataFrame - Actions

    Introduction

    DataFrame actions are operations that trigger the execution of the computation plan built using DataFrame transformations. Unlike transformations, which are lazy and merely define the computation to be performed, actions instruct Spark to execute those computations and return results back to the driver program or write them to an external system like HDFS, S3, tables e.t.c.

    Actions in Spark DataFrame typically involve reading data from external sources, collecting data to the driver program, writing data to external storage systems, or performing computations that return non-DataFrame results.

    Here are some common DataFrame actions in Spark.

    | Action | Description | | ---------- | ------------------------------------------------------------------------------------------------ | | show() | Displays the first few rows of the DataFrame in a tabular format. | | collect() | Retrieves all rows from the DataFrame and brings them to the driver program as an array. | | take() | Retrieves the first N rows from the DataFrame and brings them to the driver program as an array. | | count() | Returns the number of rows in the DataFrame. | | first() | Returns the first row of the DataFrame. | | head() | Returns the first N rows of the DataFrame as an array. | | foreach() | Applies a function to each row of the DataFrame. | | write() | Writes the DataFrame to external storage systems like HDFS, S3, or databases. | | save() | Saves the DataFrame to an external storage system. | | toPandas() | Converts the DataFrame to a Pandas DataFrame. | | toDF() | Converts a list of tuples or RDD into a DataFrame. |

    These actions trigger the execution of the computation plan and return results or write data as specified. It's important to note that actions are usually the last operations in a Spark program, as they trigger the actual computation and materialization of results.

    Apache Spark Tutorial with Scala Examples — DataFrame Introduction

    Introduction to Apache Spark

    Setup Apache Spark Environment

    SparkSession & SparkContext

    Resilient Distributed Datasets (RDDs)

    Apache Spark Concepts

    Cache, Persistence and Shared Variables

    DataFrame Introduction

    DataFrame Narrow Transformation

    DataFrame Wider Transformation

    DataFrame Actions

    Spark SQL Functions

    Advanced DataFrame Features

    Using SQL Queries

    Spark Read & Write CSV Files

    Working with JSON Files

    Working with Parquet Files

    Spark Dataset

    What Next?

    Tutorial Not Found