DataFrame.from_query() Function

Teradata® Python Package User Guide

brand
Teradata Vantage
prodname
Teradata Python Package
vrm_release
16.20
category
User Guide
featnum
B700-4006-098K

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

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: 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: 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