DataFrame.from_query() Function - Teradata Python Package

Teradata® Python Package User Guide

Product
Teradata Python Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-29
dita:mapPath
rkb1531260709148.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage

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