ToTabular
ToTabular[data,form]
converts from data with structure specified by form.
ToTabular[data,form,assoc]
uses directives from the association assoc to give details of the conversion.
Details and Options
- ToTabular is typically used to provide control over how data objects are converted into Tabular objects.
- The data argument can include:
-
matrix rectangular matrix of data » array array of data, rectangular in the first two levels » {assoc1,assoc2,...} list of associations » Dataset[…] Dataset near-rectangular data of any depth » TimeSeries[…] TimeSeries data with univariate or multivariate values TemporalData[…] TemporalData data of any number of paths SpatialPointData[…] SpatialPointData data » - The structure specification in the "form" argument can include:
-
"Rows" row-oriented 2D data "Columns" column-oriented data "Dataset" multidimensional data "TimeSeries" TimeSeries objects "TemporalData" TemporalData objects "SpatialPointData" SpatialPointData objects - Arrays can be converted with the following additional elements of the association assoc:
-
"ColumnKeys" Automatic names of columns » "ColumnLevels" Automatic levels to flatten into columns "RowLevels" Automatic levels to flatten into rows "HeaderRows" 0 number of rows to use as column keys » - For array data, a specification {"RowLevels"rlevs,"ColumnLevels"clevs} is effectively equivalent to Flatten[data,{rlevs,clevs}].
- Dataset can be converted with the following additional elements of the assoc:
-
"ColumnKeys" Automatic names of columns » "ColumnLevels" Automatic levels to flatten into columns "RowLevels" Automatic levels to flatten into rows "LevelNames" Automatic key column names corresponding to levels - TimeSeries and TemporalData can be converted with the following additional elements of the association assoc:
-
"ComponentsToColumns" Automatic whether to split multivariate values into columns - In addition, the specification assoc can include for any "form" value:
-
"CacheOriginalExpression" True whether to cache a copy of the input »
Examples
open allclose allBasic Examples (4)
Scope (18)
Array Data (6)
Construct a Tabular object from a matrix of data:
Convert an array of depth 3 into a Tabular object:
With the default structure, the array is considered as 2D with list elements:
Specify "Dataset" form to consider that data as 3D—it will flatten the first two dimensions into rows:
Use the "ColumnLevels" directive to specify which levels get flattened into rows or columns:
Equivalent shape obtained by Flatten:
Arrays must be rectangular in the first two levels:
Raggedness in the second level is not accepted:
By default, all rows of the input are interpreted as data rows:
Interpret the first row as headers:
The "ColumnKeys" parameter takes precedence over the keys inferred from "HeaderRows":
Import CSV data with column labels and use it to construct the column keys of a Tabular object:
List of Associations (2)
Dataset (3)
Convert a Dataset object to a Tabular object:
Using Tabular directly:
Using ToTabular allows for better control on column names:
Convert a Dataset object to a Tabular object:
Specify "RowLevels" for which level to use for rows:
Same result can be obtained using "ColumnLevels":
Take a dataset of information about male and female population in the G7 countries:
By default, the first two levels are converted into key columns of the resulting Tabular object:
Specify names for the columns of those levels:
Convert only the first Dataset level into a key column, keeping the other two in extended keys:
Time Series & Temporal Data (4)
Convert to Tabular a univariate time series starting yesterday:
Convert a multivariate time series to Tabular:
Do not split value components into separate columns:
Convert univariate multipath TemporalData to Tabular:
The time stamps are different for each path—a resampling over the union of the time stamps from all the paths with value interpolation can unify the time stamps:
Convert multipath and multicomponent TemporalData to Tabular:
Spatial Data (3)
Convert simple SpatialPointData into Tabular:
The region is stored in metadata:
Convert SpatialPointData with annotations to Tabular:
Convert multiple point configurations with annotations to Tabular:
Options (2)
MissingValuePattern (2)
By default, Tabular only interprets explicit Missing[…] expressions as missing values:
Specify a pattern for the entries that should be additionally interpreted as missing values:
Specify multiple MissingValuePattern values:
Specify patterns for the entries that should be interpreted as missing values:
Properties & Relations (2)
For simple data inputs, ToTabular[data] is equivalent to Tabular[data]:
By default, the original expression is cached when a Tabular object is created:
Therefore the original input can be recovered with Normal:
Use "CacheOriginalExpression"False to avoid caching the original data:
Then Normal will reconstruct a canonicalized form of the input:
Possible Issues (2)
Raggedness in the second level is not accepted:
Arrays must be rectangular in the first two levels:
Dataset row labels will become a column "DatasetKey" key when "LevelNames" are not specified:
Text
Wolfram Research (2025), ToTabular, Wolfram Language function, https://reference.wolfram.com/language/ref/ToTabular.html.
CMS
Wolfram Language. 2025. "ToTabular." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ToTabular.html.
APA
Wolfram Language. (2025). ToTabular. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ToTabular.html