liveBook · Manning

Create_dataframe

As explained in Snowflake Data Engineering

create_dataframe is a Snowpark session method that constructs a data frame from local data and an optional schema definition.

create_dataframe is a Snowpark session method for constructing a DataFrame from local row data and an optional schema. A StructType schema declares each column through StructField objects, including names and data types such as DateType and BooleanType. section 6.5

Listing 6.9 Constructing a data frame and defining the data structure
# create a data frame from the holiday_flags list of lists 
# and define the schema as two columns:
# - column named "day" with data type DateType
# - column named "holiday_flg" with data type BooleanType
df = my_session.create_dataframe(
    holiday_flags, 
    schema = StructType(
        [StructField("day", DateType()), 
         StructField("holiday_flg", BooleanType())])
    )

Construct a holiday dimension from holiday_flags, defining day as a date and holiday_flg as a Boolean column. section 6.5

Use the method within a Snowpark pipeline as follows:

  • Create a Snowflake connection and call create_dataframe with the local list of lists and its StructType schema. section 6.5
  • Remember that DataFrame operations are lazy; collect(), count(), show(), or save_as_table() triggers execution. section 6.5
  • Persist results with write.mode("overwrite").save_as_table() during iterative development, or append records when loading additional data. section 6.5 section 7.4.3

Convert CSV output into a table

Split CSV text into rows, remove the header, pass the resulting list of lists and a five-column schema to create_dataframe, then append the DataFrame to COLLECTED_ORDERS_FROM_EMAIL. section 7.4.3

  orders_df = session.create_dataframe(
    [x.split(',') for x in csv_output.split("\n")][1:], schema)

Inspect the concise conversion from parsed CSV rows to an orders DataFrame using a predefined schema. section 7.4.3

How Snowflake Data Engineering covers it

How deep it goes
Explains typed schema construction, lazy execution, inspection actions, and table writes without detailing broader API variations.
Examples
Uses holiday flags and parsed email CSV orders as concrete local-data inputs.
What it assumes
Requires a Snowpark session and local row data while teaching schema definition through StructType and StructField.
What you can do after
Build it from scratch by converting local rows into typed DataFrames and saving them with overwrite or append behavior.
How it connects
Connects Snowpark DataFrames with StructType schemas, DataFrame actions, lazy evaluation, and save_as_table.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Snowflake Data Engineering. The section links point to the parts of the book it draws on.