RPA.Tables
Append a column to a table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| name | str, None | None |
| values | Any, None | None |
| 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:
Append rows to a table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| values | Any, None | None |
| 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.
Examples:
Make a copy of a table object.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| param table: | Table to copy |
|---|---|
| return: | Table object |
${table_copy}= Copy table ${table}
Create Table object from data.
Arguments
| Argument | Type | Default value |
|---|---|---|
| data | Dict[int | str, Dict | List | Tuple | NamedTuple | set], List[Dict | List | Tuple | NamedTuple | set], Table, None | None |
| trim | bool | False |
| columns | List[str], None | None |
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) |
| return: | Table object |
See the main library documentation for more information about supported data types.
Usage
Convert a table object into standard Python containers.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| with_index | bool | False |
| as_list | bool | True |
| param table: | Table to convert to dict |
|---|---|
| param with_index: | Include index in values |
| param as_list: | Export data as list instead of dict |
| return: | A List or Dictionary that represents the table |
Usage
Remove all rows where column values don't match the given condition.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| column | int, str | null |
| operator | str | null |
| value | Any | null |
| 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:
Run a keyword for each row of a table, then remove all rows where the called keyword returns a falsy value.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| name | str | null |
| args | null |
Can be used to create custom RF keyword based filters.
| param table: | Table to modify. |
|---|---|
| param name: | Keyword name used as filter. |
| param args: | Additional keyword arguments to be passed. (optional) |
The row object will be given as the first argument to the filtering keyword.
Find all the rows in a table which match a condition for a given column.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| column | int, str | null |
| operator | str | null |
| value | Any | null |
| param table: | Table to search into. |
|---|---|
| param column: | Name or position of the column to compare with. |
| param operator: | Comparison operator used with every cell value on the specified column. |
| param value: | Value to compare against. |
| return: | New Table object containing all the rows matching the condition. |
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:
Get a cell value from a table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| row | int, str | null |
| column | int, str | null |
| param table: | Table to read from |
|---|---|
| param row: | Row of cell |
| param column: | Column of cell |
| return: | Cell value |
Examples:
Return table dimensions, as (rows, columns).
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| param table: | Table to inspect |
|---|---|
| return: | Two integer values that represent the number of rows and columns |
Usage
Get a single row from a table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| row | int, str | null |
| as_list | bool | False |
| param table: | Table to read |
|---|---|
| param row: | Row to read |
| param as_list: | Return list instead of dictionary |
| return: | Dictionary or List of table row |
Examples:
Return a new Table from a range of given Table rows.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| start | str, int, None | None |
| end | str, int, None | None |
| param table: | Table to read from |
|---|---|
| param start: | Start index (inclusive) |
| param start: | End index (exclusive) |
| return: | Table object of the selected rows |
If start is not defined, starts from the first row. If end is not defined, stops at the last row.
Examples:
Group a table by column and return a list of grouped Tables.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| column | int, str | null |
| param table: | Table to use for grouping |
|---|---|
| param column: | Column which is used as grouping criteria |
| return: | List of Table objects |
Usage
Run a keyword for each cell in a given column, and replace its content with the return value.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| column | int, str | null |
| name | str | null |
| args | null |
Can be used to easily convert column types or values in-place.
| param table: | Table to modify. |
|---|---|
| param column: | Column to modify. |
| param name: | Mapping keyword name. |
| param args: | Additional keyword arguments. (optional) |
The cell value will be given as the first argument to the mapping keyword.
Examples:
Create a union of two tables and their contents.
Arguments
| Argument | Type | Default value |
|---|---|---|
| tables | Table | null |
| index | str, None | None |
| param tables: | Tables to merge |
|---|---|
| param index: | Column name to use as index for merge |
| return: | Table object |
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.
Usage
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 |
Remove column from table and return it.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| column | str, int, None | None |
| param table: | Table to modify |
|---|---|
| param column: | Column to remove |
| return: | Dictionary or List of the removed, popped, column |
Examples:
Remove row from table and return it.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| row | str, int, None | None |
| as_list | bool | False |
| param table: | Table to modify |
|---|---|
| param row: | Row index, pops first row if none given |
| param as_list: | Return list instead of dictionary |
| return: | Dictionary or List of the removed, popped, row |
Examples:
Read a CSV file as a table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| path | str | null |
| header | bool, None | None |
| columns | List[str], None | None |
| dialect | str, Dialect, None | None |
| delimiters | str, None | None |
| column_unknown | str | Unknown |
| encoding | str, None | None |
| 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 |
| return: | Table object |
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.
Builtin 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:
Renames columns in the Table with given values. Columns with name as None will use the previous value.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| names | List[str | None] | null |
| strict | bool | False |
| 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:
Set a cell value in a table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| row | int, str | null |
| column | int, str | null |
| value | Any | null |
| param table: | Table to modify to |
|---|---|
| param row: | Row of cell |
| param column: | Column of cell |
| param value: | Value to set |
Examples:
Assign values to a column in the table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| column | int, str | null |
| values | Any | null |
| 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:
Assign values to a row in the table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| row | int, str | null |
| values | Any | null |
| 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:
Sort a table in-place according to column.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| column | int, str | null |
| ascending | bool | True |
| param table: | Table to sort |
|---|---|
| param column: | Column to sort with |
| param ascending: | Table sort order |
Examples:
Return first count rows from a table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| count | int | 5 |
| as_list | bool | False |
| param table: | Table to read from |
|---|---|
| param count: | Number of lines to read |
| param as_list: | Return list instead of Table |
| return: | Return Table object or List of the selected rows |
Usage
Return last count rows from a table.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| count | int | 5 |
| as_list | bool | False |
| param table: | Table to read from |
|---|---|
| param count: | Number of lines to read |
| param as_list: | Return list instead of Table |
| return: | Return Table object or List of the selected rows |
Usage
Write a table as a CSV file.
Arguments
| Argument | Type | Default value |
|---|---|---|
| table | Table | null |
| path | str | null |
| header | bool | True |
| dialect | str, Dialect | Excel |
| encoding | str, None | None |
| delimiter | str, None | , |
| 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 |
| param delimiter: | Delimiter character between columns |
Builtin dialect values are excel, excel-tab, and unix.