LoginSignup
0
0

More than 3 years have passed since last update.

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

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')

このoutがCASTableオブジェクトになります。

CASTableオブジェクトについて

まずは出力してみます。

out
§ caslib
CASUSER(dev@sas.com)

§ tableName
IRIS

§ casTable
CASTable('IRIS', caslib='CASUSER(dev@sas.com)')

elapsed 0.00764s · user 0.003s · sys 0.008s · mem 20.8MB

キーでアクセスする

まずはキーでアクセスします。

out['tableName']
# 'IRIS'
out['caslib']
# 'CASUSER(dev@sas.com)'
out['casTable']
# CASTable('IRIS', caslib='CASUSER(dev@sas.com)')

プロパティでアクセスする

続いてプロパティを使った例です。

out.casTable
# CASTable('IRIS', caslib='CASUSER(dev@sas.com)')

テーブル情報の取得

テーブル情報を表示するには下記のように行います。

out.casTable.tableinfo()
§ TableInfo
Name Rows Columns IndexedColumns Encoding CreateTimeFormatted ModTimeFormatted AccessTimeFormatted JavaCharSet CreateTime ... Global Repeated View SourceName SourceCaslib Compressed Creator Modifier SourceModTimeFormatted SourceModTime
0 IRIS 150 5 0 utf-8 2019-07-02T22:17:57-04:00 2019-07-02T22:17:57-04:00 2019-07-02T22:17:57-04:00 UTF8 1.877739e+09 ... 0 0 0 0 dev@sas.com 2019-07-02T22:17:56-04:00 1.877739e+09

1 rows × 22 columns



elapsed 0.00108s · sys 0.001s · mem 0.69MB

カラム情報を表示する

columninfo でカラム情報が取得できます。

out.casTable.columninfo()
§ ColumnInfo
Column ID Type RawLength FormattedLength NFL NFD
0 SepalLength 1 double 8 12 0 0
1 SepalWidth 2 double 8 12 0 0
2 PetalLength 3 double 8 12 0 0
3 PetalWidth 4 double 8 12 0 0
4 Name 5 varchar 15 15 0 0



elapsed 0.00118s · user 0.000999s · mem 0.72MB

データを取得する

データはfetchメソッドで取得できます。

out.casTable.fetch(to=5)
§ Fetch
Selected Rows from Table IRIS
SepalLength SepalWidth PetalLength PetalWidth Name
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa



elapsed 0.00303s · user 0.003s · mem 0.865MB

データの概要を見る

データの概要は summary メソッドで確認できます。

out.casTable.summary()
§ Summary
Descriptive Statistics for IRIS
Column Min Max N NMiss Mean Sum Std StdErr Var USS CSS CV TValue ProbT Skewness Kurtosis
0 SepalLength 4.3 7.9 150.0 0.0 5.843333 876.5 0.828066 0.067611 0.685694 5223.85 102.168333 14.171126 86.425375 3.331256e-129 0.314911 -0.552064
1 SepalWidth 2.0 4.4 150.0 0.0 3.054000 458.1 0.433594 0.035403 0.188004 1427.05 28.012600 14.197587 86.264297 4.374977e-129 0.334053 0.290781
2 PetalLength 1.0 6.9 150.0 0.0 3.758667 563.8 1.764420 0.144064 3.113179 2583.00 463.863733 46.942721 26.090198 1.994305e-57 -0.274464 -1.401921
3 PetalWidth 0.1 2.5 150.0 0.0 1.198667 179.8 0.763161 0.062312 0.582414 302.30 86.779733 63.667470 19.236588 3.209704e-42 -0.104997 -1.339754



elapsed 0.0035s · user 0.004s · mem 1.99MB

テーブルの所有者情報

テーブルの所有者に関する情報は userinfo メソッドを使います。

out.casTable.userinfo()
§ userInfo
{'userId': 'dev@sas.com', 'providedName': 'dev@sas.com', 'uniqueId': 'dev@sas.com', 'groups': ['sas', 'openid', '_PDC_pdcesx13078'], 'providerName': 'OAuth/External PAM', 'anonymous': False, 'hostAccount': True, 'guest': False}

elapsed 0.000348s · user 0.001s · mem 0.212MB

テーブルのカラムを確認する

カラムは columns プロパティに入っています。

out.casTable.columns
# Index(['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth', 'Name'], dtype='object')

さらにデータ型などを知りたいときには dtypes を使います。

out.casTable.dtypes
# SepalLength     double
# SepalWidth      double
# PetalLength     double
# PetalWidth      double
# Name           varchar
# dtype: object

まとめて確認する際にはinfoを使うのが便利です。

out.casTable.info()
# CASTable('IRIS', caslib='CASUSER(dev@sas.com)')
# Data columns (total 5 columns):
#                N   Miss     Type
# SepalLength  150  False   double
# SepalWidth   150  False   double
# PetalLength  150  False   double
# PetalWidth   150  False   double
# Name         150  False  varchar
# dtypes: double(4), varchar(1)
# data size: 9200
# vardata size: 2000
# memory usage: 9232

まとめ

CASTableはSAS Viyaを使う上での基本的なテーブルになります。データ分析を行う際には必須になりますので、ぜひ使い方を覚えてください。

SAS for Developers | 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