Teradata Package for Python Function Reference on VantageCloud Lake - create_view - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Package for Python
Release Number
20.00.00.08
Published
November 2025
ft:locale
en-US
ft:lastEdition
2025-12-05
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.dataframe.DataFrame.create_view = create_view(self, view_name, schema_name=None)
Creates a view from the DataFrame object in the specified schema.
As teradataml creates views, internally for operations, which will be garbage
collected during remove_context(), this function helps the user to persist the
DataFrame as a view.
Note:
    The persisted view can be used across sessions and can be accessed
    using the view_name and schema_name.
 
PARAMETERS:
    view_name:
        Required Argument.
        Specifies the name of the view to be persisted.
        Types: str
 
    schema_name:
        Optional Argument.
        Specifies the schema name where the view is to be persisted.
        Note:
            If the schema_name is not provided, the current database will be used.
        Types: str
 
RETURNS:
    Persisted teradataml DataFrame.
 
RAISES:
    TeradataMlException
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("antiselect", ["antiselect_input"])
    >>> antiselect_input = DataFrame.from_table("antiselect_input")
    >>> antiselect_input
            orderid orderdate       priority  quantity       sales  discount        shipmode            custname province   region     custsegment          prodcat
    rowids
    49          293  12/10/01           high        49  10123.0200      0.07  delivery truck        barry french  nunavut  nunavut        consumer  office supplies
    97          613  11/06/17           high        12     93.5400      0.03     regular air        carl jackson  nunavut  nunavut       corporate  office supplies
    85          515  10/08/28  not specified        19    394.2700      0.08     regular air      carlos soltero  nunavut  nunavut        consumer  office supplies
    86          515  10/08/28  not specified        21    146.6900      0.05     regular air      carlos soltero  nunavut  nunavut        consumer        furniture
    1             3  10/10/13            low         6    261.5400      0.04     regular air  muhammed macintyre  nunavut  nunavut  small business  office supplies
    50          293  12/10/01           high        27    244.5700      0.01     regular air        barry french  nunavut  nunavut        consumer  office supplies
    80          483  11/07/10           high        30   4965.7595      0.08     regular air       clay rozendal  nunavut  nunavut       corporate       technology
 
    # Filter the data based on quantity.
    >>> anti_df = antiselect_input[antiselect_input.quantity < 30]
    >>> anti_df
            orderid orderdate       priority  quantity   sales  discount     shipmode            custname province   region     custsegment          prodcat
    rowids
    97          613  11/06/17           high        12   93.54      0.03  regular air        carl jackson  nunavut  nunavut       corporate  office supplies
    86          515  10/08/28  not specified        21  146.69      0.05  regular air      carlos soltero  nunavut  nunavut        consumer        furniture
    85          515  10/08/28  not specified        19  394.27      0.08  regular air      carlos soltero  nunavut  nunavut        consumer  office supplies
    1             3  10/10/13            low         6  261.54      0.04  regular air  muhammed macintyre  nunavut  nunavut  small business  office supplies
    50          293  12/10/01           high        27  244.57      0.01  regular air        barry french  nunavut  nunavut        consumer  office supplies
 
    # Run Antiselect on filtered data. This will create temporary view which will be garbage collected.
    >>> obj = Antiselect(data=anti_df, exclude=['rowids', 'orderdate', 'discount', 'province', 'custsegment'])
    
    # Get the view name that is internally created by teradataml to store the result of Antiselect.
    >>> obj.result.db_object_name
    '"<schema_name>"."ml__td_sqlmr_out__1752582812690000"'
 
    # Check the output of Antiselect.
    >>> obj.result
    orderid       priority  quantity   sales     shipmode            custname   region          prodcat
    0      613           high        12   93.54  regular air        carl jackson  nunavut  office supplies
    1      515  not specified        21  146.69  regular air      carlos soltero  nunavut        furniture
    2      515  not specified        19  394.27  regular air      carlos soltero  nunavut  office supplies
    3      293           high        27  244.57  regular air        barry french  nunavut  office supplies
    4        3            low         6  261.54  regular air  muhammed macintyre  nunavut  office supplies
 
    # Describe the resultant DataFrame.
    >>> df = obj.result.describe() # This will create a temporary view.
    
    # Get the view name.
    >>> df.db_object_name
    '"<schema_name>"."ml__td_sqlmr_out__1752585435339977"'
 
    # Check the output of describe.
    >>> df
      ATTRIBUTE            StatName   StatValue
    0   orderid             MAXIMUM  613.000000
    1   orderid  STANDARD DEVIATION  245.016734
    2   orderid     PERCENTILES(25)  293.000000
    3   orderid     PERCENTILES(50)  515.000000
    4  quantity               COUNT    5.000000
    5  quantity             MINIMUM    6.000000
    6  quantity             MAXIMUM   27.000000
    7  quantity                MEAN   17.000000
    8  quantity  STANDARD DEVIATION    8.154753
    9  quantity     PERCENTILES(25)   12.000000
 
    # Example 1: Persist the view which can be accessed across sessions.
    >>> df_new = df.create_view(view_name="antiselect_describe_view")
    >>> df_new
      ATTRIBUTE            StatName   StatValue
    0  quantity             MAXIMUM   27.000000
    1  quantity  STANDARD DEVIATION    8.154753
    2  quantity     PERCENTILES(25)   12.000000
    3  quantity     PERCENTILES(50)   19.000000
    4     sales               COUNT    5.000000
    5     sales             MINIMUM   93.540000
    6   orderid               COUNT    5.000000
    7   orderid             MINIMUM    3.000000
    8   orderid             MAXIMUM  613.000000
    9   orderid                MEAN  387.800000
 
    # Get the view name.
    >>> df_new.db_object_name # "<schema_name>" is user connected database.
    '"<schema_name>"."antiselect_describe_view"'