Example: Create teradatamlspk DataFrame for data in a Vantage Table or View - Example: Create teradatamlspk DataFrame for Data in a Vantage Table or View - Teradata Package for Python

Teradata® pyspark2teradataml User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-11
dita:mapPath
oeg1710443196055.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
oeg1710443196055
Product Category
Teradata Vantage

The teradatamlspk API TeradataSession exposes an API createDataFrame which takes input as table name and returns teradatamlspk DataFrame. With the APIs, you can create teradatamlspk DataFrame for data resides in a Vantage table or view.

See following steps. This example assumes the table 'admissions_train' is already loaded with data.

  • >>> from teradatamlspk.sql import TeradataSession
    >>> tdmkspk = TeradataSession.builder.getOrCreate(host=host, user = user, password=password)
    
  • >>> df = tdmlspk.createDataFrame("admissions_train")
    >>> df.show()
    +--+-------+----+--------+-----------+--------+
    |id|masters|gpa | stats  |programming|admitted|
    +--+-------+----+--------+-----------+--------+
    |15|  yes  |4.0 |Advanced|  Advanced |   1    |
    |14|  yes  |3.45|Advanced|  Advanced |   0    |
    |31|  yes  |3.5 |Advanced|  Beginner |   1    |
    |40|  yes  |3.95| Novice |  Beginner |   0    |
    |22|  yes  |3.46| Novice |  Beginner |   0    |
    |39|  yes  |3.75|Advanced|  Beginner |   0    |
    |37|   no  |3.52| Novice |   Novice  |   1    |
    |35|   no  |3.68| Novice |  Beginner |   1    |
    |38|  yes  |2.65|Advanced|  Beginner |   1    |
    |26|  yes  |3.57|Advanced|  Advanced |   1    |
    |5 |   no  |3.44| Novice |   Novice  |   0    |
    |3 |   no  |3.7 | Novice |  Beginner |   1    |
    |1 |  yes  |3.95|Beginner|  Beginner |   0    |
    |17|   no  |3.83|Advanced|  Advanced |   1    |
    |34|  yes  |3.85|Advanced|  Beginner |   0    |
    |13|   no  |4.0 |Advanced|   Novice  |   1    |
    |32|  yes  |3.46|Advanced|  Beginner |   0    |
    |11|   no  |3.13|Advanced|  Advanced |   1    |
    |9 |   no  |3.82|Advanced|  Advanced |   1    |
    |24|   no  |1.87|Advanced|   Novice  |   1    |
    +--+-------+----+--------+-----------+--------+
    only showing top 20 rows