Note: You are looking at a static snapshot of documentation related to Robot Framework automations. The most recent documentation is at https://robocorp.com/docs

RPA.Tables

Tables is a library for manipulating tabular data inside Robot Framework.

It can import data from various sources and apply different operations to it. Common use-cases are reading and writing CSV files, inspecting files in directories, or running tasks using existing Excel data.

Import types

The data a table can be created from can be of two main types:

  1. An iterable of individual rows, like a list of lists, or list of dictionaries
  2. A dictionary of columns, where each dictionary value is a list of values

For instance, these two input values:

data1 = [ {"name": "Mark", "age": 58}, {"name": "John", "age": 22}, {"name": "Adam", "age": 67}, ] data2 = { "name": ["Mark", "John", "Adam"], "age": [ 58, 22, 67], }

Would both result in the following table:

IndexNameAge
0Mark58
1John22
2Adam67

Indexing columns and rows

Columns can be referred to in two ways: either with a unique string name or their position as an integer. Columns can be named either when the table is created, or they can be (re)named dynamically with keywords. The integer position can always be used, and it starts from zero.

For instance, a table with columns "Name", "Age", and "Address" would allow referring to the "Age" column with either the name "Age" or the number 1.

Rows do not have a name, but instead only have an integer index. This index also starts from zero. Keywords where rows are indexed also support negative values, which start counting backwards from the end.

For instance, in a table with five rows, the first row could be referred to with the number 0. The last row could be accessed with either 4 or -1.

Examples

Robot Framework

The Tables library can load tabular data from various other libraries and manipulate it inside Robot Framework.

*** Settings *** Library RPA.Tables *** Keywords *** Files to Table ${files}= List files in directory ${CURDIR} ${files}= Create table ${files} Filter table by column ${files} size >= ${1024} FOR ${file} IN @{files} Log ${file}[name] END Write table to CSV ${files} ${OUTPUT_DIR}${/}files.csv

Python

The library is also available directly through Python, where it is easier to handle multiple different tables or do more bespoke manipulation operations.

from RPA.Tables import Tables library = Tables() orders = library.read_table_from_csv( "orders.csv", columns=["name", "mail", "product"] ) customers = library.group_table_by_column(rows, "mail") for customer in customers: for order in customer: add_cart(order) make_order()