5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Teradata® Package for Python Function Reference [リリース番号:17.10 リリース日付:2022/4]の翻訳です。

はじめに

PythonでVantageのデータを取得する方法を説明します。
ライブラリとしてteradatamlを利用します。

teradatamlはTeradata Vantage用のPythonライブラリです。

基本操作

Vantageに接続する

python code
# 接続用ライブラリの宣言
import teradataml as tdml
# データベース接続
tdml.create_context(host = "IPアドレス",username='ユーザ名',password='パスワード')

テーブルを指定してデータを取得する

python code
# Customerテーブルのデータをteradatamlデータフレームに読み込む
tdml.DataFrame.from_table("Customer")
結果を表示
               Customer_Name   Segment        Country          City         State   PostalCode   Region
Customer_ID                                                                                            
MJ-17740           Max Jones  Consumer  United States          Orem          Utah        84057     West
MJ-17740           Max Jones  Consumer  United States     Lancaster          Ohio        43130     East
MJ-17740           Max Jones  Consumer  United States       Seattle    Washington        98115     West
MJ-17740           Max Jones  Consumer  United States  Philadelphia  Pennsylvania        19140     East
KW-16435     Katrina Willman  Consumer  United States      Florence      Kentucky        41042    South
KW-16435     Katrina Willman  Consumer  United States       Chicago      Illinois        60653  Central
KW-16435     Katrina Willman  Consumer  United States        Austin         Texas        78745  Central
MJ-17740           Max Jones  Consumer  United States       Detroit      Michigan        48227  Central
MJ-17740           Max Jones  Consumer  United States         Miami       Florida        33178    South
MJ-17740           Max Jones  Consumer  United States     San Diego    California        92037     West

SQLを指定してデータを取得する

python code
# SQLの結果データをteradatamlデータフレームに読み込む
tdml.DataFrame.from_query("select * from Customer where city = 'San Diego'")
結果を表示
               Customer_Name      Segment        Country       City       State   PostalCode Region
Customer_ID                                                                                        
JG-15805          John Grady    Corporate  United States  San Diego  California        92105   West
JF-15355            Jay Fein     Consumer  United States  San Diego  California        92105   West
AA-10645       Anna Andreadi     Consumer  United States  San Diego  California        92105   West
OT-18730         Olvera Toch     Consumer  United States  San Diego  California        92105   West
JW-15220           Jane Waco    Corporate  United States  San Diego  California        92105   West
RA-19285        Ralph Arnett     Consumer  United States  San Diego  California        92037   West
BT-11530     Bradley Talbott  Home Office  United States  San Diego  California        92037   West
DS-13180         David Smith    Corporate  United States  San Diego  California        92037   West
MJ-17740           Max Jones     Consumer  United States  San Diego  California        92037   West
JE-15610             Jim Epp    Corporate  United States  San Diego  California        92105   West

Vantageから切断する

python code
# データベース切断
tdml.remove_context()

おわりに

警告
この本書はTeradata Vantageドキュメンテーションよりトピックに必要な情報を抜粋したものです。掲載内容の正確性・完全性・信頼性・最新性を保証するものではございません。正確な内容については、原本をご参照下さい。
また、修正が必要な箇所や、ご要望についてはコメントをよろしくお願いします。

Teradata Vantageへのお問合せ

Teradata Vantage へのお問合せ

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?