DataFrame Constructor | Teradata Python Package - DataFrame Constructor - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2022-01-14
dita:mapPath
bol1585763678431.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage

Use DataFrame() function to create a teradataml DataFrame from an existing table or view in Vantage.

Arguments:

The function takes a table name or view name as argument and creates a DataFrame based on the table or view in Vantage.

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 for a table, the primary index of the base table is used as the index label.
  • If the index label is not specified for a view, the index label is set to None.

Example 1: Create a DataFrame from an existing table "sales" in Vantage

The index label is not specified, the primary index "accounts" is used.

>>> df = DataFrame("sales")
>>> df
              Feb   Jan   Mar   Apr  datetime
accounts                                    
Alpha Co    210.0   200   215   250  04/01/2017
Red Inc     200.0   150   140  None  04/01/2017
Orange Inc  210.0  None  None   250  04/01/2017
Jones LLC   200.0   150   140   180  04/01/2017
Yellow Inc   90.0  None  None  None  04/01/2017
Blue Inc     90.0    50    95   101  04/01/2017
>>>

Example 2: Create a DataFrame from an existing table "sales" in Vantage with an index label "Feb"

>>> df = DataFrame("sales", index_label="Feb")
>>> df
         accounts   Jan   Mar   Apr  datetime
Feb                                         
210.0    Alpha Co   200   215   250  04/01/2017
200.0     Red Inc   150   140  None  04/01/2017
210.0  Orange Inc  None  None   250  04/01/2017
200.0   Jones LLC   150   140   180  04/01/2017
90.0   Yellow Inc  None  None  None  04/01/2017
90.0     Blue Inc    50    95   101  04/01/2017

Example 3: Create a DataFrame from an existing table "sales" in Vantage with an index label "Jan" and "Feb"

>>> df = DataFrame("sales", index_label=["Jan", "Feb"])
>>> df
             accounts   Mar   Apr  datetime
Jan Feb                                   
200 210.0    Alpha Co   215   250  04/01/2017
150 200.0     Red Inc   140  None  04/01/2017
NaN 210.0  Orange Inc  None   250  04/01/2017
150 200.0   Jones LLC   140   180  04/01/2017
NaN 90.0   Yellow Inc  None  None  04/01/2017
50  90.0     Blue Inc    95   101  04/01/2017

Example 4: Creates a DataFrame from an existing view "salesv" in Vantage with an index_label "Mar"

To use this example, one must create a view on sales table at the backend with name 'salesv'. If not created, user will not be able to run this example.
>>> get_context().execute("CREATE VIEW salesv AS SELECT * FROM sales")
<sqlalchemy.engine.result.ResultProxy object at 0x11bbc3668>
>>> df = DataFrame("salesv", index_label="Mar")
>>> df
       accounts    Feb   Jan   Apr  datetime
Mar                                        
95     Blue Inc   90.0    50   101  04/01/2017
NaN  Orange Inc  210.0  None   250  04/01/2017
140     Red Inc  200.0   150  None  04/01/2017
NaN  Yellow Inc   90.0  None  None  04/01/2017
140   Jones LLC  200.0   150   180  04/01/2017
215    Alpha Co  210.0   200   250  04/01/2017