Skip to main content
Table

Think of this as a list of namedtuples, except the elements of the namedtuples can be edited. The table is initialized with a list of column header names. Appending to the table adds new rows. Rows are created using a list (positional) or dict (column names). Unspecified column cells default to None.

Other list methods (insert, pop, remove, extend, reverse) work as expected. sort allows a string key to indicate a sort-by-column. Search methods (index, count, __contains__) accept either a Row object or a list or dict.

Additional methods useful for tables:

  • take(indexes_or_func) returns a new table based on passed in indexes Alternatively, applies a function to every row in the table and builds a new table out of rows that evaluate to True

  • column(colname) returns an iterator over values in a column

LookupTable

A lookup function or column is added to a basic Table. The lookup function is similar to a hash function, taking a Row object and returning a value. If a column is provided, the value in that column is the lookup value. A dict keeps track of these “lookup” values, allowing fast lookups on all seach methods (index, count, __contains__). These search methods accept either a Row object (which is run through the lookup function) or the lookup value. The lookup values do not need to be unique.

Example

from datetime import datetime, date, timedelta
from roundtable import Table
# Create empty table with column headers
tbl = Table(['Timestamp', 'Event', 'Root Cause', 'Due Date'])
# Add rows to the table
tbl.append((datetime(2013,1,2,12,30), 'Error code 129',
            'Short on board', date(2013,1,8)))
tbl.append({'Event': 'Pairwise testing',
            'Due Date': date(2013,1,7)}) # other columns default to None
# Build a sorted list of tasks due in the next week
task_list = tbl.take(lambda row: row['Due Date'] - date.today() < timedelta(days=7))
task_list.sort(col='Due Date', reverse=True)

Table access methods:

Code

Return Type

mytable[0]

Row object

mytable[-1]

Row object

mytable[0:10:2]

new Table object

mytable[0][0]

value in cell

mytable[0][-1]

value in cell

mytable[0, 0]

value in cell

mytable[0]['a column']

value in cell

mytable[0, 'a column']

value in cell

mytable[0].Col2

value in cell*

mytable.column(1)

iterator over values in column

mytable.column('a column')

iterator over values in column

* As a special case, if a column name is a valid Python variable name and starts with a capital letter then an attribute will be added to the Row object allowing access. The requirement to start with a capital letter avoids conflicts with other attributes and functions of the Row object.

Table objects can be transformed into other table-like objects if modules are available:

  • NumPy Array : mytable.as_array()

  • Pandas DataFrame: mytable.as_dataframe()

Note

Works for Python 2.6+, 3.1+

No dependencies except when using the as_array() or as_dataframe() methods.

Metadata

Release files for roundtable 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distributions (sdists)

Source distribution for roundtable 0.4
File Size Uploaded
roundtable-0.4.zip 11.6 kB Details
roundtable-0.4.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for roundtable 0.4
File Interpreter ABI Platform
roundtable-0.4.win32.exe Details

Total release size: 231.7 kB

Release files / roundtable-0.4.zip

Download URL roundtable-0.4.zip
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d034c8c8a2b76e107065e4494515cb986ac4a4a8d700d81e4bd0c157ceb5318e
BLAKE2b-256 checksum
How to use checksums
65a5197c5d65476f6a3865b28edecb3ee15963db8608387c1eafdaee273b7761
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / roundtable-0.4.tar.gz

Download URL roundtable-0.4.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ff0647466768b76f7936d4a5db6821db1721a53e08a5984190e546f185e93f9b
BLAKE2b-256 checksum
How to use checksums
3b7dbfff1dbf3af631bdade6fc90ce528274d171e88add1cca0cc4268db909f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / roundtable-0.4.win32.exe

Download URL roundtable-0.4.win32.exe
Size 211.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f7bf42ef420848f4228150ddf259f9d0ea866b986b146e746807b68d6e774b2e
BLAKE2b-256 checksum
How to use checksums
44a198bc45cc31c30414d042b5aecc9df7bf5d3a1e30fe465ccd08635b68dc6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4 This release

3 release files

0.3

3 release files

0.2

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page