riptable.rt_accumtable

Classes

AccumTable

AccumTable is a wrapper on Accum2 that enables the creation of tables that

Functions

accum_cols(cat, val_list[, name_list, filt_list, ...])

Compute multiple accum calculations on the same categorical label, output as a single dataset.

accum_ratio(cat1[, cat2, val1, val2, filt1, filt2, ...])

Compute a bucketed ratio of two accums, using AccumTable.

accum_ratiop(cat1[, cat2, val, filter, func, norm_by, ...])

Compute an internal ratio, either by Total (T), Row (R), or Column (C).

class riptable.rt_accumtable.AccumTable(cat_rows, cat_cols, filter=None, showfilter=False)

Bases: riptable.rt_accum2.Accum2

AccumTable is a wrapper on Accum2 that enables the creation of tables that combine the results of multiple reductions generated from the Accum2 object. The three parts of a table generated by the AccumTable gen() method are these:

  • Inner Table - a table of values indexed by row labels and column key names. A generated table contains only one inner table, but any number of inner tables may be created and used to create margin columns and footer rows, or as a reference for display formatting (future functionality).

  • Margin Columns - columns of values on the right margin, associated with an inner table, and indexed by and representing a value associated with a given row label. Call set_margin_columns() to adjust them.

  • Footer Rows - rows of values on the bottom margin, associated with an inner table and indexed by and representing a value associated with a given column key. Call set_footer_rows() to adjust them.

Parameters:
  • cat_rows (Categorical or an array converted to same) – The array used to create the row labels in the AccumTable

  • cat_cols (Categorical or an array converted to same) – The array used to create the column keys in the AccumTable

  • filter (ndarray) – Boolean mask array applied as filter before constructing the groupings

  • showfilter (bool) – Whether to include groupings whose values were all filtered out

__getitem__(index)
Parameters:

index (str) – Inner table name

Returns:

The specified inner table

Return type:

Dataset

Raises:

IndexError – If index is not a string (table name).

__repr__()

Return a string representation of the object

Returns:

The repr string

Return type:

str

__setitem__(name, ds)
Parameters:
  • name (str) – Inner table name

  • ds (Dataset) – The dataset

Raises:
_rename_summary_row_and_col(ds, new_name)
Parameters:
  • ds (Dataset) – The dataset

  • new_name (str) – the new name for the summary column and footer row

Return type:

Dataset

gen(table_name=None, format=None, ref_table=None, remove_blanks=True)

Generate an AccumTable view.

Parameters:
  • table_name (string or tuple (not implemented yet)) – The name of the AccumTable table to display, or a tuple of table names if more than one value is to be displayed in each cell (not implemented yet).

  • yet) (ref_table (not implemented) – A dictionary used to specify the formatting of each cell in the table. The keys are formatting types, such as ‘bold’, ‘color’, and ‘background’, and the values are functions that are applied to the value (or tuple) in each table cell to determine the applicability of a formatting type. For example, once could set format={‘bold’: lambda v: v > 0} to make all positive values in the table bold.

  • yet) – The name of the AccumTable table, or a Dataset of the same shape, to be referenced for formatting the displayed table (not implemented yet).

  • remove_blanks (bool) – Do not display rows or columns containing all zeros or NaNs

Returns:

The generated table

Return type:

Dataset

Examples

View the pnl values in the table, coloring negative values red (not implemented yet):

>>> at.gen('pnl', format={'color': lambda v: return 'red' if v < 0 else 'black'})

Specify the names of the inner tables whose footer rows should appear in the generated AccumTable view.

Parameters:

rows (list) – The list of inner table names, in order.

set_margin_columns(cols)

Specify the names of the inner tables whose margin columns should appear in the generated AccumTable view.

Parameters:

cols (list of str) – The list of inner table names, in order.

riptable.rt_accumtable.accum_cols(cat, val_list, name_list=None, filt_list=None, func_list='nansum', remove_blanks=False)

Compute multiple accum calculations on the same categorical label, output as a single dataset.

Parameters:
  • cat (Categorical) – Categorical label to group by

  • val_list (list) – List of data columns. If an element is a two-element list itself, a ratio will be calculated. If an element is a two-element list of type [val, ‘p’], an accum_ratiop-style percentile will be calculated

  • name_list (list) – List of column names in the eventual dataset. Defaults to colN.

  • filt_list (list) – List of filters, either one for all or one for each. Defaults to truecol.

  • func_list (str or list of str) – String of function name (or list of strings of function names) to pass into AccumTable call, either one for all or one for each. Defaults to ‘nansum’.

  • remove_blanks (bool) – If set to true, blanks will be removed from the output. Defaults to True.

Returns:

Accum2 view of calculated data.

Return type:

Dataset

riptable.rt_accumtable.accum_ratio(cat1, cat2=None, val1=None, val2=None, filt1=None, filt2=None, func1='nansum', func2=None, return_table=False, include_numer=False, include_denom=True, remove_blanks=False)

Compute a bucketed ratio of two accums, using AccumTable.

Parameters:
  • cat1 (Categorical) – First categorical label to group by.

  • cat2 (Categorical, optional) – Second categorical label to group by.

  • val1 – Numerator data

  • val2 – Denominator data

  • filt1 – Filter for val1 data

  • filt2 – Filter for val2 data. Optional, defaults to filter1

  • func1 – String of function name to pass into numerator AccumTable call

  • func2 – String of function name to pass into denominator AccumTable call. Defaults to func1.

  • include_numer (bool) – If set to True, include the totals from the numerator data in the output. Ignored if return_table is True.

  • include_denom (bool) – If set to True, include the totals from the denominator data in the output. Ignored if return_table is True.

  • return_table (bool) – If set to True, returns the whole AccumTable instead of just the gen’d ratio data.

  • remove_blanks (bool) – If set to True, blanks will be removed from the output.

Returns:

Either a view of the ratio data, or the entire AccumTable, depending on return_table flag.

Return type:

Dataset or AccumTable

riptable.rt_accumtable.accum_ratiop(cat1, cat2=None, val=None, filter=None, func='nansum', norm_by='T', include_total=True, remove_blanks=False, filt=None)

Compute an internal ratio, either by Total (T), Row (R), or Column (C).

Parameters:
  • cat1 (Categorical) – First categorical label to group by

  • cat2 (Categorical, optional) – Second categorical label to group by.

  • val – Data column

  • filter (boolean column) – Filter for var data. Replacing filt.

  • func (str) – String of function name to pass into AccumTable call

  • norm_by ({'T', 'C', 'R'}) – what to use as the denominator

  • include_total (bool) – Include the total amounts in addition to the ratios, defaults to True.

  • remove_blanks (bool) – If set to True, blanks will be removed from the output; defaults to True.

  • filt – DEPRECATED FOR “filter”.

Returns:

AccumTable view of ratios

Return type:

Dataset