LoslegenKostenlos loslegen

Create a SQL table from a dataframe

A dataframe can be used to create a temporary table. A temporary table is one that will not exist after the session ends. Spark documentation also refers to this type of table as a SQL temporary view. In the documentation this is referred to as to register the dataframe as a SQL temporary view. This command is called on the dataframe itself, and creates a table if it does not already exist, replacing it with the current data from the dataframe if it does already exist.

Diese Übung ist Teil des Kurses

Introduction to Spark SQL in Python

Kurs anzeigen

Anleitung zur Übung

  • Load csv data from the file trainsched.txt into a dataframe stored in a variable named df.
  • Create a temporary table from df. Call the table "table1".

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Load trainsched.txt
df = spark.____.____("trainsched.txt", header=True)

# Create temporary table called table1
df.____(____)
Code bearbeiten und ausführen