Add Table Column

Append a column to a table.

Arguments

Argument Type Default value Description
tableTablenull
namestr, NoneNone
valuesAny, NoneNone
param table:Table to modify
param name:Name of new column
param values:Value(s) for new column

The values can either be a list of values, one for each row, or one single value that is set for all rows.

Examples:

*** Tasks ***
# Add empty column
Add table column    ${table}

# Add empty column with name
Add table column    ${table}    name=Home Address

# Add new column where every every row has the same value
Add table column    ${table}    name=TOS    values=${FALSE}

# Add new column where every row has a unique value
${is_first}=    Create list    ${TRUE}    ${FALSE}    ${FALSE}
Add table column    ${table}    name=IsFirst    values=${is_first}

Add Table Row

Append rows to a table.

Arguments

Argument Type Default value Description
tableTablenull
valuesAny, NoneNone
param table:Table to modify
param values:Value(s) for new row

The values can either be a list of values, or a dictionary where the keys match current column names. Values for unknown keys are discarded.

It can also be a single value that is set for all columns, which is None by default.

Example:s

*** Tasks ***
# Add empty row
Add table row    ${table}

# Add row where every column has the same value
Add table row    ${table}    Unknown

# Add values per column
${values}=    Create dictionary    Username=Mark    Mail=mark@robocorp.com
Add table row    ${table}    ${values}

Clear Table

Clear table in-place, but keep columns.

Arguments

Argument Type Default value Description
tableTablenull
param table:Table to clear

Copy Table

Make a copy of a table object.

Arguments

Argument Type Default value Description
tableTablenull
param table:Table to copy

Create Table

Create Table object from data.

Arguments

Argument Type Default value Description
dataDict[typing.Union[int, str], typing.Union[typing.Dict, typing.List, typing.Tuple, typing.NamedTuple, set]], List[typing.Union[typing.Dict, typing.List, typing.Tuple, typing.NamedTuple, set]], Table, NoneNone
trimboolFalse
columnsList[str], NoneNone

Data can be a combination of various iterable containers, e.g. list of lists, list of dicts, dict of lists.

param data:Source data for table
param trim:Remove all empty rows from the end of the worksheet, default False
param columns:Names of columns (optional)

See the main library documentation for more information about supported data types.

Export Table

Convert a table object into standard Python containers.

Arguments

Argument Type Default value Description
tableTablenull
with_indexboolFalse
as_listboolTrue
param table:Table to convert to dict
param with_index:
 Include index in values
param as_list:Export data as list instead of dict

Examples

*** Tasks ***
${orders}=       Read worksheet as table    orders.xlsx
Sort table by column    ${orders}    CustomerId
${export}=       Export table    ${orders}
# The following keyword expects a dictionary:
Write as JSON    ${export}

Filter Empty Rows

Remove all rows from a table which have only ``None`` values.

Arguments

Argument Type Default value Description
tableTablenull

Remove all rows from a table which have only None values.

param table:Table to filter

The filtering will be done in-place.

Examples

*** Tasks ***
${table}=    Read worksheet as table    orders.xlsx
Filter empty rows    ${table}

Filter Table By Column

Remove all rows where column values don't match the given condition.

Arguments

Argument Type Default value Description
tableTablenull
columnint, strnull
operatorstrnull
valueAnynull

Remove all rows where column values don't match the given condition.

param table:Table to filter
param column:Column to filter with
param operator:Filtering operator, e.g. >, <, ==, contains
param value:Value to compare column to (using operator)

See the keyword Find table rows for all supported operators and their descriptions.

The filtering will be done in-place.

Examples:

*** Tasks ***
# Only accept prices that are non-zero
Filter table by column    ${table}   price  !=  ${0}

# Remove uwnanted product types
@{types}=    Create list    Unknown    Removed
Filter table by column    ${table}   product_type  not in  ${types}

Find Table Rows

Find all rows in a table which match a condition for a given column.

Arguments

Argument Type Default value Description
tableTablenull
columnint, strnull
operatorstrnull
valueAnynull

Find all rows in a table which match a condition for a given column.

param table:Table to find from
param column:Name of column to search
param operator:Comparison operator
param value:Value to compare against

Supported operators:

Operator Description
> Cell value is larger than
< Cell value is smaller than
>= Cell value is larger or equal than
<= Cell value is smaller or equal than
== Cell value is equal to
!= Cell value is not equal to
is Cell value is the same object
not is Cell value is not the same object
contains Cell value contains given value
not contains Cell value does not contain given value
in Cell value is in given value
not in Cell value is not in given value

Returns the matches as a new Table instance.

Examples:

*** Tasks ***
# Find all rows where price is over 200
@{rows}=    Find table rows    Price  >  ${200}

# Find all rows where the status does not contain "removed"
@{rows}=    Find table rows    Status    not contains    removed

Get Table Cell

Get a cell value from a table.

Arguments

Argument Type Default value Description
tableTablenull
rowintnull
columnint, strnull
param table:Table to read from
param row:Row of cell
param column:Column of cell

Examples:

*** Tasks ***
# Get the value in the first row and first column
Get table cell    ${table}    0    0

# Get the value in the last row and first column
Get table cell    ${table}   -1    0

# Get the value in the third row and column "Name"
Get table cell    ${table}    2    Name

Get Table Column

Get all values for a single column in a table.

Arguments

Argument Type Default value Description
tableTablenull
columnint, strnull
param table:Table to read
param column:Column to read

Examples

*** Tasks ***
${emails}=    Get table column    ${users}    E-Mail Address
FOR    ${email}    IN    @{emails}
    Send promotion    ${email}
END

Get Table Dimensions

Return table dimensions, as (rows, columns).

Arguments

Argument Type Default value Description
tableTablenull
param table:Table to inspect

Examples:

*** Tasks ***
${rows}  ${columns}=    Get table dimensions    ${table}
Log    Table has ${rows} rows and ${columns} columns.

Get Table Row

Get a single row from a table.

Arguments

Argument Type Default value Description
tableTablenull
rowintnull
as_listboolFalse
param table:Table to read
param row:Row to read
param as_list:Return list instead of dictionary

Examples:

*** Tasks ***
${first}=    Get table row    ${orders}
Log     Handling order: ${first}[Order ID]

${row}=      Get table row    ${data}    -1    as_list=${TRUE}
FOR    ${value}    IN    @{row}
    Log    Data point: ${value}
END

Get Table Slice

Return a new Table from a range of given Table rows.

Arguments

Argument Type Default value Description
tableTablenull
startint, NoneNone
endint, NoneNone
param table:Table to read from
param start:Start index (inclusive)
param start:End index (exclusive)

If start is not defined, starts from the first row. If end is not defined, stops at the last row.

Examples:

*** Tasks ***
# Get all rows except first five
${slice}=    Get table slice    ${table}    start=5

# Get rows at indexes 5, 6, 7, 8, and 9
${slice}=    Get table slice    ${table}    start=5    end=10

# Get all rows except last five
${slice}=    Get table slice    ${table}    end=-5

Group Table By Column

Group a table by ``column`` and return a list of grouped Tables.

Arguments

Argument Type Default value Description
tableTablenull
columnint, strnull

Group a table by column and return a list of grouped Tables.

param table:Table to use for grouping
param column:Column which is used as grouping criteria

Examples

*** Tasks ***
${orders}=    Read worksheet as table    orders.xlsx
@{groups}=    Group table by column    ${orders}    customer
FOR    ${group}    IN    @{groups}
    # Process all orders for the customer at once
    Process order    ${group}
END

Merge Tables

Create a union of two tables and their contents.

Arguments

Argument Type Default value Description
tablesTablenull
indexstr, NoneNone
param tables:Tables to merge
param index:Column name to use as index for merge

By default rows from all tables are appended one after the other. Optionally a column name can be given with index, which is used to merge rows together.

Examples

For instance, a name column could be used to identify unique rows and the merge operation should overwrite values instead of appending multiple copies of the same name.

Name Price
Egg 10.0
Cheese 15.0
Ham 20.0
Name Stock
Egg 12.0
Cheese 99.0
Ham 0.0
*** Tasks ***
${products}=    Merge tables    ${prices}    ${stock}    index=Name
FOR    ${product}    IN    @{products}
    Log many
    ...    Product: ${product}[Name]
    ...    Price: ${product}[Price]
    ...    Stock: ${product}[Stock]
END

Pop Table Column

Remove column from table and return it.

Arguments

Argument Type Default value Description
tableTablenull
columnint, str, NoneNone
param table:Table to modify
param column:Column to remove

Examples:

*** Tasks ***
# Remove column from table and discard it
Pop table column    ${users}   userId

# Remove column from table and iterate over it
${ids}=    Pop table column    ${users}    userId
FOR    ${id}    IN    @{ids}
    Log    User id: ${id}
END

Pop Table Row

Remove row from table and return it.

Arguments

Argument Type Default value Description
tableTablenull
rowint, NoneNone
as_listboolFalse
param table:Table to modify
param row:Row index, pops first row if none given
param as_list:Return list instead of dictionary

Examples:

*** Tasks ***
${first}=    Pop table row    ${orders}
Log     Handling order: ${first}[Order ID]

${row}=      Pop table row    ${data}    -1    as_list=${TRUE}
FOR    ${value}    IN    @{row}
    Log    Data point: ${value}
END

Read table from CSV

Read a CSV file as a table.

Arguments

Argument Type Default value Description
pathstrnull
headerbool, NoneNone
columnsList[str], NoneNone
dialectDialect, NoneNone
delimitersstr, NoneNone
column_unknownstrUnknown
encodingstr, NoneNone
param path:Path to CSV file
param header:CSV file includes header
param columns:Names of columns in resulting table
param dialect:Format of CSV file
param delimiters:
 String of possible delimiters
param column_unknown:
 Column name for unknown fields
param encoding:Text encoding for input file, uses system encoding by default

By default attempts to deduce the CSV format and headers from a sample of the input file. If it's unable to determine the format automatically, the dialect and header will have to be defined manually.

Valid dialect values are excel, excel-tab, and unix, and header is boolean argument (True/False). Optionally a set of valid delimiters can be given as a string.

The columns argument can be used to override the names of columns in the resulting table. The amount of columns must match the input data.

If the source data has a header and rows have more fields than the header defines, the remaining values are put into the column given by column_unknown. By default it has the value "Unknown".

Examples:

*** Tasks ***
# Source dialect is deduced automatically
${table}=    Read table from CSV    export.csv
Log   Found columns: ${table.columns}

# Source dialect is known and given explicitly
${table}=    Read table from CSV    export-excel.csv    dialect=excel
Log   Found columns: ${table.columns}

Rename Table Columns

Renames columns in the Table with given values. Columns with name as ``None`` will use the previous value.

Arguments

Argument Type Default value Description
tableTablenull
namesList[typing.Union[str, NoneType]]null
strictboolFalse

Renames columns in the Table with given values. Columns with name as None will use the previous value.

param table:Table to modify
param names:List of new column names
param strict:If True, raises ValueError if column lengths do not match

The renaming will be done in-place.

Examples:

*** Tasks ***
${columns}=    Create list   First  Second  Third
Rename table columns    ${table}    ${columns}
# First, Second, Third


${columns}=    Create list   Uno  Dos
Rename table columns    ${table}    ${columns}
# Uno, Dos, Third

Set Row As Column Names

Set existing row as names for columns.

Arguments

Argument Type Default value Description
tableTablenull
rowintnull
param table:Table to modify
param row:Row to use as column names

Examples:

*** Tasks ***
${table}=    Read table from CSV    data.csv
Set row as column names    ${table}    0

Set Table Cell

Set a cell value in a table.

Arguments

Argument Type Default value Description
tableTablenull
rowintnull
columnint, strnull
valueAnynull
param table:Table to modify to
param row:Row of cell
param column:Column of cell
param value:Value to set

Examples:

*** Tasks ***
# Set the value in the first row and first column to "First"
Set table cell    ${table}    0    0       First

# Set the value in the last row and first column to "Last"
Set table cell    ${table}   -1    0       Last

# Set the value in the third row and column "Name" to "Unknown"
Set table cell    ${table}    2    Name    Unknown

Set Table Column

Assign values to entire column in the table.

Arguments

Argument Type Default value Description
tableTablenull
columnint, strnull
valuesAnynull
param table:Table to modify
param column:Column to modify
param values:Value(s) to set

The values can either be a list of values, one for each row, or one single value that is set for all rows.

Examples:

*** Tasks ***
# Set different value for each row (sizes must match)
${ids}=    Create list    1  2  3  4  5
Set table column    ${users}    userId    ${ids}

# Set the same value for all rows
Set table column    ${users}    email     ${NONE}

Set Table Row

Assign values to a row in the table.

Arguments

Argument Type Default value Description
tableTablenull
rowintnull
valuesAnynull
param table:Table to modify
param row:Row to modify
param values:Value(s) to set

The values can either be a list of values, or a dictionary where the keys match current column names. Values for unknown keys are discarded.

It can also be a single value that is set for all columns.

Examples:

*** Tasks ***
${columns}=  Create list     One  Two  Three
${table}=    Create table    columns=${columns}

${values}=   Create list     1  2  3
Set table row    ${table}    0    ${values}

${values}=   Create dictionary    One=1  Two=2  Three=3
Set table row    ${table}    1    ${values}

Set table row    ${table}    2    ${NONE}

Sort Table By Column

Sort a table in-place according to ``column``.

Arguments

Argument Type Default value Description
tableTablenull
columnint, strnull
ascendingboolFalse

Sort a table in-place according to column.

param table:Table to sort
param column:Column to sort with
param ascending:
 Table sort order

Examples

*** Tasks ***
${orders}=    Read worksheet as table    orders.xlsx
Sort table by column    ${orders}    order_date

Table Head

Return first ``count`` rows from a table.

Arguments

Argument Type Default value Description
tableTablenull
countint5
as_listboolFalse

Return first count rows from a table.

param table:Table to read from
param count:Number of lines to read
param as_list:Return list instead of Table

Examples:

*** Tasks ***
# Get the first 10 employees
${employees}=    Read worksheet as table    employees.xlsx
${first}=        Table head    ${employees}    10

Table Tail

Return last ``count`` rows from a table.

Arguments

Argument Type Default value Description
tableTablenull
countint5
as_listboolFalse

Return last count rows from a table.

param table:Table to read from
param count:Number of lines to read
param as_list:Return list instead of Table

Examples:

*** Tasks ***
# Get the last 10 orders
${orders}=    Read worksheet as table    orders.xlsx
${latest}=    Table tail    ${orders}    10

Trim Column Names

Remove all extraneous whitespace from column names.

Arguments

Argument Type Default value Description
tableTablenull
param table:Table to filter

The filtering will be done in-place.

Examples

*** Tasks ***
${table}=    Read table from CSV    data.csv
Log    ${table.columns}  # "One", "Two ", "  Three "
Trim column names     ${table}
Log    ${table-columns}  # "One", "Two", "Three"

Trim Empty Rows

Remove all rows from the *end* of a table which have only ``None`` as values.

Arguments

Argument Type Default value Description
tableTablenull

Remove all rows from the end of a table which have only None as values.

param table:Table to filter

The filtering will be done in-place.

Examples

*** Tasks ***
${table}=    Read worksheet as table    orders.xlsx
Trim empty rows    ${table}

Write table to CSV

Write a table as a CSV file.

Arguments

Argument Type Default value Description
tableTablenull
pathstrnull
headerboolTrue
dialectDialectExcel
encodingstr, NoneNone
param table:Table to write
param path:Path to write to
param header:Write columns as header to CSV file
param dialect:The format of output CSV
param encoding:Text encoding for output file, uses system encoding by default

Valid dialect values are Excel, ExcelTab, and Unix.

Examples

*** Tasks ***
${sheet}=    Read worksheet as table    orders.xlsx    header=${TRUE}
Write table to CSV    ${sheet}    output.csv