XPORT (.stx,.xpt)
XPORT (.stx,.xpt)
予備知識
-
- MIMEタイプ:application/x-sas-xport
- SAS XPORTの転送形式.
- レガシーデータ交換形式.
- 数値データセットをポータブル形式で保持する.
- テキスト形式.
- 1980年代後半にSAS Instituteによって開発された.
ImportとExport
- Import["file.xpt"]はXPORTファイルをインポートして,すべてのデータセットを表として並べて返す.
- XPORTデータはWolfram言語では,実数,整数,文字列,ブール値のTrueとFalse,およびDateList指定によって表される.
- Import["file.xpt",elem]は指定された要素をXPORTファイルからインポートする.
- Import["file.xpt",{elem,suba,subb,…}]はサブ要素をインポートする.
- インポート形式はImport["file","XPORT"]またはImport["file",{"XPORT",elem,…}]で指定できる.
- Export["file.xpt",expr] は expr からXPORTファイルを作成する.
- サポートされている式 expr:
-
{v1,v2,…} 1列のデータ {{v11,v12,…},{v21,v22,…},…} データの行のリスト array SparseArray,QuantityArray等の配列 tseries TimeSeries,EventSeries,TemporalDataオブジェクト Dataset[…] データ集合 Tabular[…] 表形式オブジェクト <|"name1"expr1,…|> 名前付きの列の連想 - Import と Export は以下のデータ形式をサポートする:
-
"Date" 日付と時間の指定 "Integer8" 8ビット整数 "Integer16" 16ビット整数 "Integer32" 32ビット整数 "Real32" IEEE単精度数 "Real64" IEEE倍精度数 "String" 文字列 - 一般的な情報は,以下の関数ページを参照のこと.
-
Import, Export ファイルからインポートする,あるいはファイルへエキスポートする CloudImport, CloudExport クラウドオブジェクトからインポートする,あるいはクラウドオブジェクトへエキスポートする ImportString, ExportString 文字列からインポートする,あるいは文字列へエキスポートする ImportByteArray, ExportByteArray バイト配列からインポートする,あるいはバイト配列へエキスポートする
要素
- 一般的なImport要素:
-
"Elements" ファイル中の有効な要素とオプションのリスト "Rules" 要素とオプションのそれぞれの規則の完全リスト "Options" オプション,特性,設定のための規則のリスト "Summary" ファイルのサイズと次元の概要 - データ表現要素:
-
"Data" 二次元配列 "Dataset" Datasetとして表された表データ "EventSeries" EventSeriesとして表された表データ "LabeledData" ラベルとデータの連想 "LabeledRawData" ラベルと生データの連想 "Tabular" Tabularオブジェクトとして表された表データ "TimeSeries" TimeSeriesとして表された表データ - Importはデフォルトで"Data"要素を使用する.
- データ記述子要素:
-
"ColumnDescriptions" 列の説明と型 "ColumnLabels" 列の名前 "ColumnTypes" 列の名前と型の連想 "MissingPositions" 欠損値とみなす要素の列ごとの位置 "MissingValues" 欠損値とみなす列ごとの値 - メタ情報要素:
-
"ByteOrdering" データのエンディアン "CharacterEncoding" ファイルの文字コード "Comments" ファイルのコメント "Compression" ファイルで使用されている圧縮のタイプ "CreationDate" DateObjectで与えられる,ドキュメントの作成日 "Dimensions" データの次元 "MetaInformation" 文字列と日付オブジェクトとして与えらるメタデータ "ModificationDate" DateObjectで与えられる,ドキュメントの変更日 "TableName" 表全体の名前 "Version" ファイルのSAS仕様のバージョン
オプション
- Importオプション:
-
"ColumnDefaultValues" Automatic 列名とデフォルト値の連想 "TimeColumn" Automatic "EventSeries" 要素および"TimeSeries" 要素における時間を使用する列 "TypeDefaultValues" Automatic 型とデフォルト値の連想 - Exportオプション:
-
"ColumnDescriptions" Automatic それぞれの列の説明のリスト "MetaInformation" Automatic メタ情報のタグと値の連想 - "ColumnDescriptions" には以下の設定が可能である:
-
{"label1","label2", …} 列名として与える文字列のリスト {assoc,…} 列のメタ情報として与える連想のリスト <|colassoc|> 索引あるいは列名と列のメタ情報の連想 - assoc には以下のキーが可能である:
-
"Name" 列名として与える文字列 "Description" 列の説明として与える文字列 "Type" 列の型として与える文字列 - "MetaInformation" には以下のキーが可能である:
-
"Comments" ファイル上に一般的なコメントとして与える文字列 "CreationDate" ファイルの作成日として与える日付オブジェクト "ModificationDate" ファイルの編集日として与える日付オブジェクト "TableName" 表全体の名前として与える文字列 "Version" ファイルのバージョンとして与える整数
例題
すべて開く すべて閉じる例 (3)
Import["ExampleData/sample.xpt"]Import["ExampleData/sample.xpt", "Summary"]file = Export["test.xpt", {{"String1", DateObject[{2000, 1, 1}, "Day"], Missing["NotAvailable"], 8.25}, {"String2", DateObject[{2000, 1, 2}, "Day"], 0.41, 1.44}, {"String3", DateObject[{2000, 1, 3}, "Day"], Missing["NotAvailable"], Missing["Tagged", "A"]}}]Import[file, "Tabular"]スコープ (9)
Import (3)
Import["ExampleData/sample.xpt", "Elements"]Import["ExampleData/sample.xpt", "Data"]Tabularオブジェクトとしてインポートする:
Import["ExampleData/sample.xpt", "Tabular"]Export (6)
Datasetをエキスポートする:
dataset = Dataset[{
<|"a" -> 1, "b" -> DateObject[{2000, 1, 1}, "Day"]|>,
<|"a" -> 2, "b" -> DateObject[{2000, 1, 2}, "Day"]|>,
<|"a" -> 3, "b" -> DateObject[{2000, 1, 3}, "Day"]|>}]file = Export["test.xpt", dataset];Import[file, "Dataset"]file = Export["test.xpt", {{1, 2, 3}, {4, 5, 6}}]Import[file, "Dataset"]file = Export["test.xpt", <|"a" -> {1, 2, 3}, "b" -> {4, 5, 6}|>]Import[file, "Dataset"]TimeSeriesをエキスポートする:
t = {1, 2, 5, 10, 12, 15};
v = {2, 1, 6, 5, 7, 4};ts = TimeSeries[v, {t}]file = Export["test.xpt", ts]Import[file, "Dataset"]file = Export["test.xpt", {{1., 2.}, {Missing["Tagged", "A"], 4.}}]Import[file, "Dataset"]不完全な配列は自動的に右に空欄が充填され,完全配列に変換される:
file = Export["test.xpt", {a, {d, e, f}}]Import[file, "Dataset"]Import要素 (18)
データ表現 (7)
"Data" (1)
"Dataset" (1)
"EventSeries" (1)
TabularオブジェクトをXPORTファイルにエキスポートする:
file = Export["test.xpt", Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Date" -> Association["ElementType" -> TypeSpecifier["Date"]["Integer32", "Day",
"Gregorian", 0]], "Value" -> Association["ElementType" -> "Real32"]],
"KeyColumns" -> None, "Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {5, {{NumericArray[{13150, 13151, 13152, 13153, 13156},
"Integer32"], {}, None}}, None}, "ElementType" -> "Date"["Integer32", "Day",
"Gregorian", 0]]], TabularColumn[Association["Data" ->
{NumericArray[{11.819999694824219, 12.039999961853027, 12.09000015258789,
11.880000114440918, 12.430000305175781}, "Real32"], {}, None},
"ElementType" -> "Real32"]]}}]]]]];XPORTファイルをEventSeriesとしてインポートする:
Import[file, "EventSeries"]"LabeledData" (1)
"LabeledRawData" (1)
"Tabular" (1)
"TimeSeries" (1)
TabularオブジェクトをXPORTファイルにエキスポートする:
file = Export["test.xpt", Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Date" -> Association["ElementType" -> TypeSpecifier["Date"]["Integer32", "Day",
"Gregorian", 0]], "Value" -> Association["ElementType" -> "Real32"]],
"KeyColumns" -> None, "Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {5, {{NumericArray[{13150, 13151, 13152, 13153, 13156},
"Integer32"], {}, None}}, None}, "ElementType" -> "Date"["Integer32", "Day",
"Gregorian", 0]]], TabularColumn[Association["Data" ->
{NumericArray[{11.819999694824219, 12.039999961853027, 12.09000015258789,
11.880000114440918, 12.430000305175781}, "Real32"], {}, None},
"ElementType" -> "Real32"]]}}]]]]];XPORTファイルをTimeSeriesとしてインポートする:
Import[file, "TimeSeries"]データ記述子 (4)
"ColumnDescriptions" (1)
"ColumnLabels" (1)
"ColumnTypes" (1)
メタデータ (7)
"Comments" (1)
"CreationDate" (1)
"Dimensions" (1)
"MetaInformation" (1)
"ModificationDate" (1)
"TableName" (1)
Importオプション (3)
"ColumnDefaultValues" (1)
Normal[Lookup[Import["ExampleData/sample.xpt", "LabeledRawData"], {"Missing", "MissingTagged"}]]//Function[...]"ColumnDefaultValues"を使って特定の列に別のデフォルト値を指定する:
Normal[Lookup[Import["ExampleData/sample.xpt", "LabeledRawData", "ColumnDefaultValues" -> <|"Missing" -> -1., "MissingTagged" -> -10.|>], {"Missing", "MissingTagged"}]]//Function[...]"TimeColumn" (1)
TabularオブジェクトをXPORTファイルにエキスポートする:
file = Export["test.xpt", Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Date" -> Association["ElementType" -> TypeSpecifier["Date"]["Integer32", "Day",
"Gregorian", 0]], "Value" -> Association["ElementType" -> "Real32"]],
"KeyColumns" -> None, "Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {5, {{NumericArray[{13150, 13151, 13152, 13153, 13156},
"Integer32"], {}, None}}, None}, "ElementType" -> "Date"["Integer32", "Day",
"Gregorian", 0]]], TabularColumn[Association["Data" ->
{NumericArray[{11.819999694824219, 12.039999961853027, 12.09000015258789,
11.880000114440918, 12.430000305175781}, "Real32"], {}, None},
"ElementType" -> "Real32"]]}}]]]]];デフォルトでは,"TimeSeries"要素および"EventSeries"要素の時間列が自動的に選択される:
Import[file, "TimeSeries"]"TimeColumn"オプションを使って時間列を指定する:
Import[file, "TimeSeries", "TimeColumn" -> "Value"]"TypeDefaultValues" (1)
Normal[Lookup[Import["ExampleData/sample.xpt", "LabeledRawData"], {"Missing", "MissingTagged"}]]//Function[...]"TypeDefaultValues"を使って特定の型に別のデフォルト値を指定する:
Normal[Lookup[Import["ExampleData/sample.xpt", "LabeledRawData", "TypeDefaultValues" -> <|"Real64" -> -1.|>], {"Missing", "MissingTagged"}]]//Function[...]Exportオプション (2)
"ColumnDescriptions" (1)
Export["test.xpt", {{1, 2., "3"}, {4, 5., "6"}}]Import["test.xpt", "ColumnDescriptions"]"ColumnDescriptions"を使って,列の型や概要を特定できる:
Export["test.xpt", {{1, 2., "3"}, {4, 5., "6"}}, "ColumnDescriptions" -> {<|"Type" -> "String", "Description" -> "String data."|>}]Import["test.xpt", "ColumnDescriptions"]"MetaInformation" (1)
関連するガイド
-
▪
- インポートとエキスポート ▪
- 全形式のリスト ▪
- 数値データ形式 ▪
- 統計的データ解析 ▪
- 表とスプレッドシート形式 ▪
- 時系列と事象系列の形式