DataFrame.from_query() Function | Teradata Python Package - DataFrame.from_query() Function - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
December 2024
ft:locale
en-US
ft:lastEdition
2025-01-23
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
Product Category
Teradata Vantage

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