Table.format
formatcolumnsformatlocaleerror_on_missing_columnson_problems
Group: Conversions
Aliases: to_char, to_string, to_text
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 providedformatvalue.format: The type-dependent format string to use to format the values. Ifformatis""orNothing, default value format is used. In case of date/time columns, the format can also be aDate_Time_Formatter. Ifformatis aColumn, 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 aDate_Time_Formatteris provided forformat, then this locale will override the locale in the formatter (unless it isdefault).error_on_missing_columns: IfTrue, an error is raised if a specified column is not found. IfFalse, the missing column is ignored.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
| Name | Location | Active | Date |
|---|---|---|---|
| John | Massachusetts | True | 2020-01-01 |
| Paul | London | False | 2020-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
| Name | Location | Active |
|---|---|---|
| John | Massachusetts | Yes |
| Paul | London | No |
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
| Name | Location | Date |
|---|---|---|
| John | Massachusetts | 20200101 |
| Paul | London | 20200102 |
Errors
- If a column in
columnsis not in the input table, aMissing_Input_Columnsis raised as an error, unlesserror_on_missing_columnsis set toFalse, in which case the problem is reported according to theon_problemssetting. - If a provided
formatvalue 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_Selectederror 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 |.