load_example_data() Function | Teradata Package for Python - load_example_data() Function - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

The load_example_data() is a helper function that loads the sample datasets.

Teradata Package for Python offers APIs and each API provides examples. To test these examples, you need the sample datasets loaded in Vantage.

The load_example_data() function can only be used in a restricted way. Function arguments only accept predetermined values as shown in the given examples here and in the Teradata Package for Python Function Reference on VantageCloud Lake.

function_name
This required argument contains the prefix name of the example JSON file to be used to load data.
You must specify the function_name values as specified in the example sections of corresponding teradataml APIs. If any other string is passed as prefix input, an error is raised as 'prefix_str_example.json' file not found. This *_example.json file contains the schema information for the tables that can be loaded using this JSON file.
table_name

This required argument specifies the name or names of the table or tables to be created in the database.

Table names provided here must have an equivalent datafile (CSV) present at teradataml/data. Schema information for the same must also be present in function_name_example.json as shown in 'function_name' argument description.
  • The function creates a new table in Vantage with the name specified in the table_name argument. You must manually drop the table if required.
  • If a table with the name provided for table_name argument already exists, this function skips creation and loading of the dataset.
  • Database used for loading table depends on the following conditions:
    • If the configuration option temp_table_database is set, then the tables are loaded in the database specified in this option.
    • If the configuration option temp_table_database is not set and the temp_database_name argument is used while creating context, then the tables are loaded in the database specified in the temp_database_name argument.
    • If none are specified, the tables are created in the default database of the connecting users or the connecting database.

Example 1: When connection is created without temp_database_name, table is loaded in default database of users

>>> from teradataml import *
>>> con = create_context(host = 'tdhost', username='tduser', password = 'tdpassword')
>>> load_example_data("pack", "ville_temperature")
# Create a teradataml DataFrame.
>>> df = DataFrame("ville_temperature")

Example 2: When connection is created with temp_database_name, table is loaded in that database

This examples shows when connection is created with the temp_database_name argument, then tables are loaded in the database specified in the temp_database_name argument.

This example also demonstrates loading multiple tables in a single function call.

>>> con = create_context(host = 'tdhost', username='tduser', password = 'tdpassword', temp_database_name = "temp_db")
>>> load_example_data("GLM", ["admissions_train", "housing_train"])
# Create teradataml DataFrames.
>>> admission_train = DataFrame(in_schema("temp_db", "admissions_train"))
>>> housing_train = DataFrame(in_schema("temp_db", "housing_train"))

Example 3: When connection is created with temp_database_name and the configuration option temp_table_database is set

This example shows when connection is created with temp_database_name and the configuration option temp_table_database is also specified, the table is created in the database specified in the configuration option temp_table_database.

>>> from teradataml import *
>>> con = create_context(host = 'tdhost', username='tduser', password = 'tdpassword', temp_database_name = "temp_db")
>>> configure.temp_table_database = "temp_db1"
>>> load_example_data("pack", "ville_temperature")
# Create a teradataml DataFrame.
>>> df = DataFrame(in_schema("temp_db1", "ville_temperature"))