5
3

More than 1 year has passed since last update.

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

はじめに

Pythonでteradatamlデータフレームの結合方法について説明します。
ライブラリとしてteradatamlを利用します。

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

基本操作

Vantageに接続する

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

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

python code
# Customerテーブルのデータをteradatamlデータフレームに読み込む
teradataml_iris = tdml.DataFrame.from_table("iris_table")

データフレームを2つに分割する

python code
teradataml_df1 = teradataml_iris.select(['idx','sepallength','sepalwidth'])
teradataml_df2 = teradataml_iris.select(['idx','petallength','petalwidth'])

teradataml_df1の中身を確認

python code
teradataml_df1
結果を表示
     sepallength  sepalwidth
idx                         
122          7.7         2.8
91           6.1         3.0
116          6.5         3.0
95           5.7         3.0
10           5.4         3.7
144          6.7         3.3
109          7.2         3.6
24           4.8         3.4
6            4.6         3.4
118          7.7         2.6

teradataml_df2の中身を確認

python code
teradataml_df2
結果を表示
     petallength  petalwidth
idx                         
40           1.3         0.3
128          5.6         2.1
49           1.4         0.2
108          5.8         1.8
137          5.5         1.8
14           1.2         0.2
8            1.4         0.2
35           1.2         0.2
70           4.8         1.8
133          5.1         1.5

データフレームを結合する

python code
# df1にdf2を結合してdf3を作成する
teradataml_df3 = teradataml_df1.join(other = teradataml_df2, on = 'idx', how = 'inner', lsuffix = 't1', rsuffix = 't2')

# 結果を表示
teradataml_df3
結果を表示
   t1_idx  t2_idx  sepallength  sepalwidth  petallength  petalwidth
0     122     122          7.7         2.8          6.7         2.0
1      95      95          5.7         3.0          4.2         1.2
2     116     116          6.5         3.0          5.5         1.8
3     143     143          6.8         3.2          5.9         2.3
4     125     125          7.2         3.2          6.0         1.8
5      10      10          5.4         3.7          1.5         0.2
6       0       0          5.1         3.5          1.4         0.2
7     137     137          6.4         3.1          5.5         1.8
8      43      43          5.0         3.5          1.6         0.6
9      35      35          5.0         3.2          1.2         0.2

Vantageから切断する

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

おわりに

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

Teradata Vantageへのお問合せ

Teradata Vantage へのお問合せ

5
3
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
3