DataFrame.from_query() Function | Teradata Python Package - DataFrame.from_query() Function - Teradata VantageCloud Lake

Lake - Analyze Your Data with ClearScape Analytics™

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2026-02-20
dita:mapPath
tcl1683670667798.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
tcl1683670667798

The DataFrame.from_query() function constructs a teradataml DataFrame from the result of a SQL query.

Arguments:

The function takes a SQL query as an argument and creates a DataFrame based on the query.

The function also takes an index label as an optional argument. The index label is used for sorting. The value of the index label can be a column name or a list of column names. If the index label is not specified when creating a DataFrame for a query, the index label is set to None.

Example 1: DataFrame.from_query with no Index Label specified

This example creates the DataFrame "df" from the result of a SQL query of the table or view "sales".

>>> df = DataFrame.from_query("select Jan, Feb, datetime from sales")
>>> df
     Jan    Feb    datetime
0    NaN   90.0  2017-04-01
1  150.0  200.0  2017-04-01
2    NaN  210.0  2017-04-01
3  200.0  210.0  2017-04-01
4   50.0   90.0  2017-04-01
5  150.0  200.0  2017-04-01

Example 2: DataFrame.from_query with One-Column Index Label

This example creates the DataFrame "df" from the result of a SQL query of the table or view "sales". The index_label is composed of one column of "sales", "Jan".

>>> df = DataFrame.from_query("select Jan, Feb, datetime from sales", index_label="Jan")
>>> df
          Feb    datetime
Jan
 150.0  200.0  2017-04-01
NaN      90.0  2017-04-01
NaN     210.0  2017-04-01
 50.0    90.0  2017-04-01
 200.0  210.0  2017-04-01
 150.0  200.0  2017-04-01