0
0

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 5 years have passed since last update.

Fetchオブジェクトのパラメータ指定について

Posted at

SAS ViyaはAIプラットフォームです。PythonやJava、Rなどの言語を通して利用できます。そのSAS Viyaの中で使われているのがCASTableというテーブルオブジェクトです(CASはCloud Analytic Servicesの略です)。CASTableからデータを取得する際のパラメータをネストして与える方法について紹介します。

SAS Viyaに接続する

まずはSAS Viyaに接続します。

from swat import *

cashost='localhost'
casport=5570
useremail='dev@sas.com'
userpassword='password'
casauth='~/.authinfo'
conn = CAS(cashost, casport, useremail, userpassword, caslib="casuser")

データをアップロードする

CSVファイルのデータをアップロードします。今回は有名なIRISのデータです。

out = conn.upload('./iris.csv')

Fetchオブジェクトを取得する

Fetchオブジェクトをconnから取得します。

fa = conn.Fetch()

初期状態ではテーブルなども設定されていませんので、パラメータで指定します。

fa.set_params('table.name', 'IRIS',
              'table.caslib', 'casuser')

この時の fa の内容は次の通りです。

?.table.Fetch(sortby=dict(0=dict(formatted='raw', name='PetalLength'), 1=dict(formatted='raw', name='PetalWidth')), table=dict(caslib='casuser', name='IRIS'))

そしてソート条件を指定します。

fa.set_params('sortby.0.name', 'PetalLength',
              'sortby.0.formatted', 'raw',
              'sortby.1.name', 'PetalWidth',
              'sortby.1.formatted', 'raw')

そして出力します。

fa(to=5)

§ Fetch

Selected Rows from Table IRIS

|SepalLength|SepalWidth|PetalLength|PetalWidth | Name
|---|---|---|---|---|---|
| 0 | 4.6 | 3.6 | 1.0 | 0.2 | Iris-setosa
| 1 | 4.3 | 3.0 | 1.1 | 0.1 | Iris-setosa
| 2 | 5.0 | 3.2 | 1.2 | 0.2 | Iris-setosa
| 3 | 5.8 | 4.0 | 1.2 | 0.2 | Iris-setosa
| 4 | 4.7 | 3.2 | 1.3 | 0.2 | Iris-setosa

elapsed 0.00106s · user 0.000999s · mem 2.84MB

まとめ

Fetchオブジェクトは set_params を使って取得するデータの指定、絞り込みが簡単に行えます。ぜひ試してみてください。

Python Programming for SAS Viya | SAS

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?