ToTabular

ToTabular[data]

converts data to a Tabular object.

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:
  • matrixrectangular matrix of data »
    arrayarray 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"Automaticnames of columns »
    "ColumnLevels"Automaticlevels to flatten into columns
    "RowLevels"Automaticlevels to flatten into rows
    "HeaderRows"0number 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"Automaticnames of columns »
    "ColumnLevels"Automaticlevels to flatten into columns
    "RowLevels"Automaticlevels to flatten into rows
    "LevelNames"Automatickey column names corresponding to levels
  • TimeSeries and TemporalData can be converted with the following additional elements of the association assoc:
  • "ComponentsToColumns"Automaticwhether to split multivariate values into columns
  • In addition, the specification assoc can include for any "form" value:
  • "CacheOriginalExpression"Truewhether to cache a copy of the input »

Examples

open allclose all

Basic Examples  (4)

Construct a Tabular object from a list of rows:

Construct a Tabular object from a list of columns:

Construct a Tabular object from a matrix, specifying column names:

Construct a Tabular object from a list of associations of common keys:

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 3Dit 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:

Check if data is rectangular:

Use the "HeaderRows" specification:

List of Associations  (2)

Construct a Tabular object from a list of associations of common keys:

Keys that do not appear in all rows get assigned Missing["NotAvailable"] values:

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":

Use multiple levels:

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 patha 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:

An alternative form:

Specify multiple MissingValuePattern values:

Specify patterns for the entries that should be interpreted as missing values:

An alternative form:

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:

Avoiding caching generally produces smaller objects:

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:

Use "LevelNames" to specify a column key:

Wolfram Research (2025), ToTabular, Wolfram Language function, https://reference.wolfram.com/language/ref/ToTabular.html.

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

BibTeX

@misc{reference.wolfram_2024_totabular, author="Wolfram Research", title="{ToTabular}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/ToTabular.html}", note=[Accessed: 15-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2024_totabular, organization={Wolfram Research}, title={ToTabular}, year={2025}, url={https://reference.wolfram.com/language/ref/ToTabular.html}, note=[Accessed: 15-January-2025 ]}