Skip to main content

Table.format

formatcolumnsformatlocaleerror_on_missing_columnson_problems

Group: Conversions

Documentation

Formats specified columns to text, optionally using a specified format. The original columns are replaced by the formatted columns.

Arguments

  • columns: The columns to format. The columns can have different types, but all columns must be compatible with any provided format value.
  • format: The type-dependent format string to use to format the values. If format is "" or Nothing, default value format is used. In case of date/time columns, the format can also be a Date_Time_Formatter. If format is a Column, it must be a text column and each record is treat row by row.
  • locale: The locale in which the format should be interpreted. If a Date_Time_Formatter is provided for format, then this locale will override the locale in the formatter (unless it is default).
  • error_on_missing_columns: Specifies if a missing input column should result in an error regardless of the on_problems settings. Defaults to True.
  • on_problems: Specifies how to handle if a problem occurs, raising as a warning by default.

Returns

  • A new table with the specified columns formatted.

Examples

Format Active and Date columns in the table using the default formatter.

      table = Table.from_rows ["Name","Location","Active","Date"] [["John", "Massachusetts", True, Date.new 2020 1 1],["Paul","London", False, Date.new 2020 1 2]]
output = table.format columns=["Active", "Date"]

Returns a Table

NameLocationActiveDate
JohnMassachusettsTrue2020-01-01
PaulLondonFalse2020-01-02

Format the last boolean columns as 'Yes'/'No'.

      table = Table.from_rows ["Name","Location","Active"] [["John", "Massachusetts", True],["Paul","London", False]]
output = table.format columns=[-1] format="Yes|No"

Returns a Table

NameLocationActive
JohnMassachusettsYes
PaulLondonNo

Format dates in a column using the format yyyyMMdd.

      table = Table.from_rows ["Name","Location","Date"] [["John", "Massachusetts", Date.new 2020 1 1],["Paul","London", Date.new 2020 1 2]]
output = table.format columns=["Date"] format="yyyyMMdd"

Returns a Table

NameLocationDate
JohnMassachusetts20200101
PaulLondon20200102

Errors

  • If a column in columns is not in the input table, a Missing_Input_Columns is raised as an error, unless error_on_missing_columns is set to False, in which case the problem is reported according to the on_problems setting.
  • If a provided format value is not compatible with all selected columns, an Illegal_Argument error will be thrown, or a Date_Time_Format_Parse_Error in the case of a badly-formed date/time format.
  • If no columns have been selected for formatting, a No_Input_Columns_Selected error is raised.

Remarks

Supported Types

  • Value_Type.Date
  • Value_Type.Date_Time
  • Value_Type.Time
  • Value_Type.Integer
  • Value_Type.Float
  • Value_Type.Boolean

Value_Type.Date, Value_Type.Date_Time, Value_Type.Time formats

See https://help.enso.org/docs/using-enso/custom-formats for details.

Value_Type.Integer, Value_Type.Float formats

Numeric format strings are specified by the Java DecimalFormat class. See https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html for a complete format specification.

Value_Type.Boolean format strings

Format strings for Boolean consist of two values that represent true and false, separated by a |.