Tabular
詳細とオプション
- Tabularは,データフレーム,表,あるいは構造化データとしても知られている.
- Tabularは,一般に,各列が変数を,各行が測定値を表すデータを表すために使われる.通常は,データウィンドウのみが表示される.
- 各列は,数,文字列,日付,式のような要素型を持つ.データ項目は欠落していてもよい.
- 次は,data の可能な形式である.
-
{row1,row2,…} 行のリストとしての行列 » {assoc1,assoc2,…} 共通のキーを持つ連想のリスト » SparseArray[…],QuantityArray[…],… 特殊行列表現 » Dataset[…] 矩形データ集合 » - ToTabularを使って式のより多くの型をTabularに変換したり変換方法を詳細に制御したりすることができる.
- Tabular[data,schm]は表形式 data のスキーマを設定したり変更したりする.ここで,schm はTabularSchemaオブジェクトあるいは連想<|"prop1"val1,…|>として与えられる.
- SQLをバックエンドに持つ表形式オブジェクトは,Tabular[spec]の spec に以下の形式を使って構築できる.
-
RelationalDatabase[…] 単一の表を含むリレーショナルデータベースオブジェクト RelationalDatabase[…]"table" リレーショナルデータベースから表を選ぶ <|"RelationalDatabase"RelationalDatabase[…],"Query""table"|> データベースからの表の拡張指定 - Tabularは,Missing[],Null,Infinityのような欠落値あるいは例外的な値も認識して操作できる.
- データ要素は,Part,Select等を使って抽出できる.
- Tabularは,FromTabularあるいはNormalを使って他の形式に変換できる.
- Tabularは,TransformColumnsやAggregateRowsのような変換関数に使うことができる.
- Tabular[tabular,options] は,指定されたオプションをTabular オブジェクトに適用する.
- 次のオプションは,Tabularの全体的な外観を制御する.
-
AllowedDimensions Automatic 行数あるいは列数に対する制限 AppearanceElements Automatic 表示ビューに含める要素 BaselinePosition Automatic 周囲のテキストのベースラインに何を揃えるか BaseStyle {} 表形式のためのベーススタイル指定 ImageMargins Automatic 表示される表形式の周囲の余白 ImageSize Automatic ビューとしての表全体の大きさ Scrollbars {Automatic,Automatic} スクロールバーを含めるかどうか ScrollPosition Automatic スクロールが有効な場合のスクロール位置 - AppearanceElementsの考えられる要素には,"RowHeaders","CollapsedRowHeaders","ColumnHeaders","CollapsedColumnHeaders","Frame"および"ResizeArea"が含まれる.
- Tabularは,表形式の内容の外観を決定する以下のオプションを取る.
-
Alignment Automatic 項目の水平方向および垂直方向の配置 Background None 使用する背景色 Dividers Automatic セル間に区切り線を含めるかどうか HeaderAlignment Automatic ヘッダの水平方向および垂直方向の配置 HeaderBackground Automatic ヘッダに使用する背景色 HeaderSize Automatic ヘッダの幅および高さ HeaderStyle Automatic ヘッダのスタイル ItemDisplayFunction None 項目をフォーマットするための関数 ItemSize Automatic 各項目の幅および高さ ItemStyle {} 列および行のスタイル - コンテンツのオプションは opt<|"elem"spec,…|>という形式であり,ここで"elem"は spec が影響を与える要素を指定する.
- 次は,使用可能な要素である.
-
"Columns"{s1,s2,…} 位置によって列のスタイルを指定する "Rows"{s1,s2,…} 位置によって行のスタイルを指定する "ColumnRules"{col1s1,…} キーによって列のスタイルを指定する "RowRules"{row1s1,…} インデックスによって行のスタイルを指定する "ItemRules"{{row1,col1}s1,…} 行および列ごとに項目のスタイルを指定する "ColumnValueFunction"cf 値によって列のスタイルを指定する "RowValueFunction"rf 値によって行のスタイルを指定する "ItemValueFunction"if 値によって項目のスタイルを指定する - "Columns"および"Rows"には次の形式が使える.
-
{s1,s2,…,sn} 最初に s1から snまでを使い,その後デフォルトの値を使う s すべての場合に s を使う Cyclic[{c1,c2,…}] すべての場合に ciを巡回的に使う {s1,s2,…,Cyclic[{c1,c2,…}],sm,…,sn} 初めに siの最初のシーケンスを使い,その後 ciを巡回的に使い,最後に siの最後のシーケンスを使う {s1,s2,…,Cyclic[{}],sm,…,sn} 初めに siの最初のシーケンスを使い,最後に最後のシーケンスを使う - 列 coliは,列キー"key"または列の数値インデックス i でよい.
- 行 rowiは,Tabularがキー列を含む場合は,その行の数値インデックス i またはRowKey[{…}]でよい.
- "RowValueFunction"f は,関数 f をデータの各行に適用し,各行全体に使用する設定を返すか,各列ごとにどの設定を使用するかを示す keyval の結果のリストを返さなければならない.
- "ItemValueFunction"には次の形式を使うことができる.
-
itfn それぞれの項目の設定を生成するために itfn を使う {col1itfn1,…}} itfniを coli 列の項目の設定生成のために使う - 項目値関数に渡される引数は,項目の値である val,表形式における位置{row,col}および表形式オブジェクト tab 全体である.
- "RowValueFunction"には次の形式を使うことができる.
-
rwfn それぞれの項目の設定を生成するために rwfn を使う {col1rwfni,…}} rwfn を使って列 coli内の項目の設定を生成する - 行値関数に渡される引数は,行の要素からなる連想 assoc,表形式内の行の位置 row,および表形式オブジェクト tab 全体である.
例題
すべて開く すべて閉じる例 (5)
行列からTabularオブジェクトを作成する:
Tabular[{{1, 2, 3}, {4, 5, 6}}]列のキーを指定して,行列からTabularオブジェクトを作成する:
Tabular[{{1, x, Today}, {4, y, Tomorrow}}, {"col1", "col2", "col3"}]共通のキーを持つ連想のリストからTabularオブジェクトを作成する:
Tabular[{<|"a" -> 1, "b" -> 2, "c" -> 3|>, <|"a" -> 4, "b" -> 5, "c" -> 6|>}]列のリストからTabularオブジェクトを作成する:
ToTabular[{"a" -> {1, 4}, "b" -> {2, 5}, "c" -> {3, 6}}, "Columns"]Tabular[Dataset[{Association["a" -> 1, "b" -> 2, "c" -> 3], Association["a" -> 4, "b" -> 5, "c" -> 6]}]]スコープ (27)
表形式オブジェクトの作成 (11)
行のリストからTabularオブジェクトを構築する:
Tabular[{{"M", 8.1, 16.1}, {"M", 13.9, 29.2}, {"M", 16.1, 33.8}, {"F", 7.2, 14.7}, {"F", 14.9, 30.1}}]列名を指定して,行列からTabularオブジェクトを構築する:
Tabular[{{1, 2}, {3, 4}, {5, 6}}, {"col1", "col2"}]連想のリストからTabularオブジェクトを構築する:
Tabular[{<|"name" -> "John", "age" -> 25|>, <|"name" -> "Anne", "age" -> 20|>, <|"name" -> "Rob", "age" -> Missing[]|>}]ExtendedKeyキーを持つ連想のリストからTabularオブジェクトを構築する:
Tabular[{<|ExtendedKey["AA", "a"] -> 1, ExtendedKey["AA", "b"] -> 2|>, <|ExtendedKey["AA", "a"] -> 3, ExtendedKey["AA", "b"] -> 4|>}]QuantityArrayからTabularオブジェクトを作る:
qa = QuantityArray[RandomReal[1, {6, 3}], {"Meters", "Seconds", "Grams"}]Tabular[qa]列指向のリストデータからのTabularオブジェクトにはTransposeが必要である:
dates = RandomDate[5, DateGranularity -> "Day"]values = {1.2, 7.3, 3.8, 4.2, 4.5};Tabular[Transpose[{dates, values}], {"date", "value"}]代りにToTabularを使う:
ToTabular[{"date" -> dates, "value" -> values}, "Columns"]data = Take[ExampleData[{"Dataset", "Planets"}], 4]Tabularを変換するとデータ集合の構造が平坦化される:
Tabular[data]"CSV"のImportを使って自動的にTabularオブジェクトを取得する:
Import["ExampleData/TreesOwnedByTheCityOfChampaign.csv", "Tabular"]"TSV"ファイルをインポートする:
Import["ExampleData/RetailSales.tsv", "Tabular"]各列の型を指定して,数のTabularオブジェクトを構築する:
Tabular[{{1, 2}, {3, 4}, {5, 6}}, <|"ElementType" -> {"Integer64", "Integer16"}|>]ColumnTypes[%]Tabular[{{1, "dog", True}, {2, "cow", False}}, <|"ElementType" -> {"Integer8", "String", "Boolean"}|>]ColumnTypes[%]行が実体で列が実体の特性であるTabularオブジェクトを表示する:
EntityValue["Country", {"Area", "HighestElevation", "Population", "PopulationDensity"}, "Tabular"]データの抽出 (9)
tab = Tabular[{{1, 2}, {3, 4}}]tab[[1, 2]]単一の要素を持つTabularオブジェクトを抽出する:
tab[[{1}, {2}]]Normal[%]Tabular[{{1, 2}, {3, 4}}]%[[1]]Normal[%]Tabular[{{1, 2}, {3, 4}}]%[[All, 1]]Normal[%]tab = Tabular[{<|"a" -> 1, "b" -> 0|>, <|"a" -> 1, "b" -> 1|>, <|"a" -> 2, "b" -> 0|>, <|"a" -> 2, "b" -> 1|>}]tab[[All, "b"]]Normal[%]キー列があるTabularオブジェクトの行を抽出する:
tab = Tabular[{{"one", True, "foo"}, {"two", False, "bar"}}, <|"ColumnKeys" -> {"key", "col1", "col2"}, "KeyColumns" -> {"key"}|>]tab[Key["one"]]tab[RowKey["one"]]tab[<|"key" -> "one"|>]いくつかのキー列があるTabularオブジェクトから1行抽出する:
tab = Tabular[{{"one", True, "foo"}, {"two", False, "bar"}}, <|"ColumnKeys" -> {"key1", "key2", "col"}, "KeyColumns" -> {"key1", "key2"}|>]tab[Key[{"one", True}]]tab[RowKey[{"one", True}]]tab[<|"key1" -> "one", "key2" -> True|>]Tabularオブジェクトから複数の列を抽出する:
tab = ResourceData["Sample Tabular Data: Fisher Iris"]tab[[All, {3, 2}]]tab[[All, {"Species", "PetalLength", "SepalLength"}]]tab = ResourceData["Sample Tabular Data: Fisher Iris"]Select[tab, #SepalLength >= Quantity[7, "Centimeters"]&]tab = Tabular[{{"M", 8.1, 16.1}, {"M", 13.9, 29.2}, {"M", 16.1, 33.8}, {"F", 7.2, 14.7}, {"F", 14.9, 30.1}}, {"MF", "val1", "val2"}]ColumnKeys[tab, #ElementType === "Real64"&]tab[All, %]データクリーニング (4)
国データのTabularオブジェクトを取る:
tab = EntityValue[EntityClass["Country", "Europe"], {"Population", "Area"}, "Tabular"]ReverseSortBy[tab, "Population"]MinimalBy[tab, "Area"]Tabular[{{1, 2}, {3, 4}, {5, 6}}, {"col1", "col2"}]DeleteColumns[%, "col2"]Tabular[{{1, 2}, {3, 4}, {5, 6}}, {"col1", "col2"}]InsertColumns[%, "col3" -> {"a", "b", "c"}]Tabular[{{1, 2}, {3, 4}, {5, 6}}, {"col1", "col2"}]RenameColumns[%, "col2" -> "c2"]データの変換 (3)
times = DateRange[Today, Today + Quantity[4, "Days"]];
values = {1.2, 7.3, 3.8, 4.2, 4.5};
Tabular[Transpose[{times, values}], {"date", "value"}]ConstructColumns[%, {"day" -> Function[DayName[#date]], "value"}]dates = {"Sep 1, 2024", "Sep 2, 2024", "Sep 3, 2024"};
values = {1.2, 7.3, 3.8};
Tabular[Transpose[{dates, values}], {"date", "value"}]TransformColumns[%, "date" -> Function[FromDateString[#date]]]tab = EntityValue[EntityClass["Country", "Europe"], {"Population", "Area"}, "Tabular"]TransformColumns[tab, "Density" -> Function[#Population / #Area]]オプション (46)
Alignment (10)
Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}, Alignment -> <|"Columns" -> {Left, Center, Right}|>]列数が配置数より多い場合,後続の列にはデフォルト配置が適用される:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"Columns" -> {Center, Left}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"Columns" -> Cyclic[{Left, Right}]|>]開始と終了の列は中央揃えとし,その間の列には左揃えと右揃えを交互に適用する:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"Columns" -> {Center, Cyclic[{Left, Right}], Center}|>]開始と終了の列は左揃えとし,中間の列にはデフォルトの配置を用いる:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"Columns" -> {Left, Cyclic[{}], Left}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"ColumnRules" -> {"b" -> Left}|>]項目の配置を,その{row,col}の位置を用いて指定する:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"ItemRules" -> {{3, "b"} -> Left}|>]列"b"の値が10より大きい場合にはその行を左揃えとし,それ以外の場合には右揃えとする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"RowValueFunction" -> (If[#b > 10, Left, Right]&)|>]デフォルトの配置にしたければ,Noneを使用するとよい:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"RowValueFunction" -> (If[#b > 10, Left, None]&)|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"ItemValueFunction" -> (If[EvenQ[#], Left, Center]&)|>]Noneを使ってデフォルトの配置にする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"ItemValueFunction" -> (If[EvenQ[#], Left, None]&)|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Alignment -> <|"ItemValueFunction" -> {"b" -> (If[# > 10, Left, Right]&)}|>]Background (13)
Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}, Background -> RGBColor[0.95, 0.627, 0.1425]]Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}, Background -> <|"Columns" -> {RGBColor[0.24, 0.6, 0.8], RGBColor[0.95, 0.627, 0.1425], RGBColor[0.455, 0.7, 0.21]}|>]Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}, Background -> <|"Rows" -> {RGBColor[0.24, 0.6, 0.8], RGBColor[0.95, 0.627, 0.1425]}|>]スタイルよりも列数が多い場合は,後ろの列にデフォルトスタイルが使われる:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"Columns" -> {RGBColor[0.24, 0.6, 0.8], RGBColor[0.95, 0.627, 0.1425], RGBColor[0.455, 0.7, 0.21]}|>]スタイルよりも行数が多い場合は,後ろの行にデフォルトスタイルが使われる:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"Rows" -> {RGBColor[0.24, 0.6, 0.8], RGBColor[0.95, 0.627, 0.1425]}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"Columns" -> Cyclic[{RGBColor[0.24, 0.6, 0.8], RGBColor[0.455, 0.7, 0.21]}]|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}, {"a", "b", "c", "d", "e"}, Background -> <|"Rows" -> Cyclic[{RGBColor[0.24, 0.6, 0.8], RGBColor[0.455, 0.7, 0.21]}]|>]列の背景を最初は青,最後は赤にして,中間にはオレンジ色と緑を交互に使う:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"Columns" -> {RGBColor[0.24, 0.6, 0.8], Cyclic[{RGBColor[0.95, 0.627, 0.1425], RGBColor[0.455, 0.7, 0.21]}], RGBColor[0.922526, 0.385626, 0.209179]}|>]行の背景を最初は青,最後は赤にして,中間にはオレンジ色と緑を交互に使う:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}, {"a", "b", "c", "d", "e"}, Background -> <|"Rows" -> {RGBColor[0.24, 0.6, 0.8], Cyclic[{RGBColor[0.95, 0.627, 0.1425], RGBColor[0.455, 0.7, 0.21]}], RGBColor[0.922526, 0.385626, 0.209179]}|>]列の背景を最初は青,最後は赤にして,中間にはデフォルトスタイルを使う:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"Columns" -> {RGBColor[0.24, 0.6, 0.8], Cyclic[{}], RGBColor[0.922526, 0.385626, 0.209179]}|>]行の背景を最初は青,最後は赤にして,中間にはデフォルトスタイルを使う:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}, {"a", "b", "c", "d", "e"}, Background -> <|"Rows" -> {RGBColor[0.24, 0.6, 0.8], Cyclic[{}], RGBColor[0.922526, 0.385626, 0.209179]}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"ColumnRules" -> {"b" -> RGBColor[0.24, 0.6, 0.8]}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"RowRules" -> {2 -> RGBColor[0.24, 0.6, 0.8]}|>]RowKey[{…}]を使って行にスタイル付けする:
Tabular[{{"apple", 2, 3, 4, 5}, {"banana", 7, 8, 9, 10}, {"grape", 12, 13, 14, 15}}, <|...|>, Background -> <|"RowRules" -> {RowKey[{"banana"}] -> RGBColor[0.24, 0.6, 0.8]}|>]{row,col}位置を使って項目の背景スタイルを指定する:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"ItemRules" -> {{3, "b"} -> RGBColor[0.24, 0.6, 0.8]}|>]行の背景色を,列"b"の値が10を超える場合は赤,それ以外の場合は青にする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"RowValueFunction" -> (If[#b > 10, RGBColor[0.91, 0.318, 0.243], RGBColor[0.24, 0.6, 0.8]]&)|>]Noneを使ってデフォルトの背景スタイルにする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"RowValueFunction" -> (If[#b > 10, RGBColor[0.91, 0.318, 0.243], None]&)|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"RowValueFunction" -> {2 -> (If[#b > 10, RGBColor[0.91, 0.318, 0.243], RGBColor[0.24, 0.6, 0.8]]&)}|>]項目の値が奇数の場合は背景色を赤に,それ以外の場合は青にする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"ItemValueFunction" -> (If[EvenQ[#], RGBColor[0.91, 0.318, 0.243], RGBColor[0.24, 0.6, 0.8]]&)|>]Noneを使ってデフォルトの背景スタイルにする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"ItemValueFunction" -> (If[EvenQ[#], RGBColor[0.91, 0.318, 0.243], None]&)|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, Background -> <|"ItemValueFunction" -> {"b" -> (If[# > 10, RGBColor[0.91, 0.318, 0.243], RGBColor[0.24, 0.6, 0.8]]&)}|>]BaselinePosition (1)
{x, y, Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, BaselinePosition -> Center], z}{x, y, Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, BaselinePosition -> Bottom], z}ImageSize (5)
デフォルトで,幅はノートブックのサイズによって制限され,表示される行数も限定される:
ResourceData["Sample Tabular Data: Car Models"]名前付きサイズを使用することで,Tabularオブジェクトの表示範囲が縮小できる:
Tabular[ResourceData["Sample Tabular Data: Car Models"], ImageSize -> Small]Tabularオブジェクトの幅を制限する:
Tabular[ResourceData["Sample Tabular Data: Car Models"], ImageSize -> 300]Tabularオブジェクトの幅および高さを制限する:
Tabular[ResourceData["Sample Tabular Data: Car Models"], ImageSize -> {300, 100}]Tabularオブジェクトの全体的な高さに制限を設ける:
Tabular[ResourceData["Sample Tabular Data: Car Models"], ImageSize -> {Automatic, 100}]ItemDisplayFunction (1)
ItemDisplayFunctionを使って欠損値の表示方法を変える:
Tabular[{{9, Missing[], 2, 3, 3}, {6, 3, 1, 3, 10}, {1, 7, 4, Missing[], Missing[]}, {5, 7, 6, 4, 3}, {9, 5, 4, 9, 6}}, ItemDisplayFunction -> (If[MissingQ[#], Style["●", StandardRed], #]&)]ItemSize (1)
項目の高さをItemSizeで増加させる:
Tabular[ResourceData["Sample Tabular Data: Car Models"], ItemSize -> 3]Tabular[ResourceData["Sample Tabular Data: Car Models"], ItemSize -> {10, 3}]Cyclicを使用して,2列目から最後までに繰り返される項目サイズを割り当てる:
Tabular[ResourceData["Sample Tabular Data: Car Models"], ItemSize -> {{15, Cyclic[{5}]}, Automatic}]ItemStyle (13)
Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}, ItemStyle -> Bold]Directiveを使って複数のスタイルを一つに組み合せる:
Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}, ItemStyle -> Directive[Bold, Italic]]Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}, ItemStyle -> <|"Columns" -> {Bold, Italic, Red}|>]Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}, ItemStyle -> <|"Rows" -> {Bold, Red}|>]スタイルよりも列数が多い場合,後ろの列にはデフォルトのスタイルが使われる:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"Columns" -> {RGBColor[0.24, 0.6, 0.8], RGBColor[0.95, 0.627, 0.1425], RGBColor[0.455, 0.7, 0.21]}|>]スタイルよりも行数が多い場合,後ろの行にはデフォルトのスタイルが使われる:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"Rows" -> {RGBColor[0.24, 0.6, 0.8], RGBColor[0.95, 0.627, 0.1425]}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"Columns" -> Cyclic[{RGBColor[0.24, 0.6, 0.8], RGBColor[0.455, 0.7, 0.21]}]|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"Rows" -> Cyclic[{RGBColor[0.24, 0.6, 0.8], RGBColor[0.455, 0.7, 0.21]}]|>]列のスタイルを最初は青,最後は赤とし,中間はオレンジ色と緑を交互に使う:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"Columns" -> {RGBColor[0.24, 0.6, 0.8], Cyclic[{RGBColor[0.95, 0.627, 0.1425], RGBColor[0.455, 0.7, 0.21]}], RGBColor[0.922526, 0.385626, 0.209179]}|>]行のスタイルを最初は青,最後は赤とし,中間はオレンジ色と緑を交互に使う:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"Rows" -> {RGBColor[0.24, 0.6, 0.8], Cyclic[{RGBColor[0.95, 0.627, 0.1425], RGBColor[0.455, 0.7, 0.21]}], RGBColor[0.922526, 0.385626, 0.209179]}|>]列のスタイルを最初は青,最後は赤とし,中間はデフォルトスタイルにする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"Columns" -> {RGBColor[0.24, 0.6, 0.8], Cyclic[{}], RGBColor[0.922526, 0.385626, 0.209179]}|>]行のスタイルを最初は青,最後は赤とし,中間はデフォルトスタイルにする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"Rows" -> {RGBColor[0.24, 0.6, 0.8], Cyclic[{}], RGBColor[0.922526, 0.385626, 0.209179]}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"ColumnRules" -> {"b" -> RGBColor[0.24, 0.6, 0.8]}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"RowRules" -> {2 -> RGBColor[0.24, 0.6, 0.8]}|>]RowKey[{…}]を使って行にスタイル付けする:
Tabular[{{"apple", 2, 3, 4, 5}, {"banana", 7, 8, 9, 10}, {"grape", 12, 13, 14, 15}}, <|...|>, ItemStyle -> <|"RowRules" -> {RowKey[{"banana"}] -> RGBColor[0.24, 0.6, 0.8]}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"ItemRules" -> {{3, "b"} -> RGBColor[0.24, 0.6, 0.8]}|>]行のスタイルを,列"b"の値が10より大きい場合は赤,それ以外の場合は青にする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"RowValueFunction" -> (If[#b > 10, RGBColor[0.91, 0.318, 0.243], RGBColor[0.24, 0.6, 0.8]]&)|>]Noneを使ってデフォルトスタイルにする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"RowValueFunction" -> (If[#b > 10, RGBColor[0.91, 0.318, 0.243], None]&)|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"RowValueFunction" -> {2 -> (If[#b > 10, RGBColor[0.91, 0.318, 0.243], RGBColor[0.24, 0.6, 0.8]]&)}|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"ItemValueFunction" -> (If[EvenQ[#], RGBColor[0.91, 0.318, 0.243], RGBColor[0.24, 0.6, 0.8]]&)|>]Noneを使ってデフォルトスタイルにする:
Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"ItemValueFunction" -> (If[EvenQ[#], RGBColor[0.91, 0.318, 0.243], None]&)|>]Tabular[{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}}, {"a", "b", "c", "d", "e"}, ItemStyle -> <|"ItemValueFunction" -> {"b" -> (If[# > 10, RGBColor[0.91, 0.318, 0.243], RGBColor[0.24, 0.6, 0.8]]&)}|>]Scrollbars (1)
ScrollPosition (1)
デフォルトでは,スクロールバーは内容の左上隅を表示する位置に配置される:
Tabular[RandomReal[1, {20, 15}], ScrollPosition -> Automatic]Tabular[RandomReal[1, {20, 15}], ScrollPosition -> {250, 0}]ScrollPositionはDynamicオブジェクトでよい:
Row[{Column[{Slider[Dynamic[h], {0, 500, 1}], Tabular[RandomReal[1, {20, 15}], ScrollPosition -> Dynamic[{h, v}], Scrollbars -> False, ImageSize -> {400, 300}]}], VerticalSlider[Dynamic[v], {300, 0}]}]アプリケーション (3)
Tabularオブジェクトを使って列データを別々の列のヘディングで表示する:
name = {"Statistics", "FisherIris"};ExampleData[name, "LongDescription"]配列データと"ColumnHeadings"特性を使ってTabularオブジェクトを作成する:
tab = Tabular[ExampleData[name], ExampleData[name, "ColumnHeadings"]]ListPlot[tab -> {"SepalLength", "PetalLength"}]AggregateRows[tab, "corr" -> Function[Correlation[#SepalLength, #PetalLength]]]AggregateRows[tab, {"SepalLengthMean" -> Function[Mean[#SepalLength]], "SepalWidthMean" -> Function[Mean[#SepalWidth]], "PetalLengthMean" -> Function[Mean[#PetalLength]], "PetalWidthMean" -> Function[Mean[#PetalWidth]]}, "Species"]Tabular形式の"DuneBooks"についての情報:
EntityValue[EntityClass["Book", "DuneBooks"], {"FirstPublished", "Author", "Image"}, "Tabular"]ItemDisplayFunctionを使用してTabular列の分布グリフを表示し,そのグリフ上に現在の項目の値を示す.
まず,SmoothHistogramで分布プロットを生成する:
g = SmoothHistogram[ResourceData["Sample Tabular Data: Car Models"] -> "mpg", PlotStyle -> LightGray, Axes -> None, AspectRatio -> 1 / 3, PlotRangePadding -> Scaled[.05], PlotInteractivity -> False]mpgGlyph[v_] := Labeled[Show[g, Epilog -> {RGBColor[0.91, 0.318, 0.243], Thick, InfiniteLine[{{v, 0}, {v, 1}}]}], v, Right]mpgGlyph[20]ItemDisplayFunctionで表形式の列"mpg"に適用する:
Tabular[ResourceData["Sample Tabular Data: Car Models"],
ItemDisplayFunction -> <|"mpg" -> (mpgGlyph[#]&)|>]特性と関係 (3)
TabularQを使ってTabularオブジェクトが有効かどうかを調べる:
Tabular[{{1, 2}, {3, 4}}]TabularQ[%]Tabularオブジェクトの列はTabularColumnオブジェクトとして与えられる:
tab = Tabular[{{a, b}, {c, d}, {e, f}}]tab[All, 1]Normal[%]tab[All, 2]Normal[%]Tabularオブジェクトの行はTabularRowオブジェクトとして与えられる:
tab = Tabular[{{a, b, c}, {d, e, f}}]tab[1]Normal[%]tab[2]Normal[%]考えられる問題 (3)
Tabular入力データは,少なくとも二次元でなければならない:
Tabular[{x, y, z}]Tabular[{{x, y, z}}]Tabular[List /@ {x, y, z}]Tabular[{{a, b}, {c}}]Tabular[{{{a, b}, {c, d}}, {{A, B, X}, {C, D}}}]Tabular[PadRight[{{a, b}, {c}}, Automatic, Missing[]]]Tabularオブジェクトは繰返される列キーを持つことはできない.これを持たせるとPart抽出によって重複されたものが削除される:
tab = Tabular[{{1, True, Today}, {2, False, Tomorrow}}, {"col", "bool", "date"}]tab[[All, {"col", "col"}]]Part抽出をマップして重複列を生成する:
tab[[All, #]]& /@ {"col", "col"}列キーがないあるいは異なる列キーを持つTabularオブジェクトを作成する:
{Tabular[%], Tabular[%, {"a", "b"}]}テキスト
Wolfram Research (2025), Tabular, Wolfram言語関数, https://reference.wolfram.com/language/ref/Tabular.html (2025年に更新).
CMS
Wolfram Language. 2025. "Tabular." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/Tabular.html.
APA
Wolfram Language. (2025). Tabular. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Tabular.html
BibTeX
@misc{reference.wolfram_2026_tabular, author="Wolfram Research", title="{Tabular}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Tabular.html}", note=[Accessed: 31-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_tabular, organization={Wolfram Research}, title={Tabular}, year={2025}, url={https://reference.wolfram.com/language/ref/Tabular.html}, note=[Accessed: 31-August-2026]}