datascience.tables.Table.index_by

Table.index_by(column_or_label)[source]
Return a dict keyed by values in a column that contains lists of

rows corresponding to each value.

Args:

columns_or_labels: Name or label of a column of the Table, values of which are keys in the returned dict.

Returns:

A dictionary with values from the column specified in the argument columns_or_labels as keys. The corresponding data is a list of Row of values from the rest of the columns of the Table.

Examples:

>>> t = Table().with_columns(
...    "column1", make_array("data1", "data2", "data3", "data4"),
...    "column2", make_array(86, 51, 32, 91),
...    "column3", make_array("b", "c", "a", "a"),
...    "column4", make_array(5, 3, 6, 9)
... )
>>> t
column1 | column2 | column3 | column4
data1   | 86      | b       | 5
data2   | 51      | c       | 3
data3   | 32      | a       | 6
data4   | 91      | a       | 9
>>> t.index_by('column2')
{86: [Row(column1='data1', column2=86, column3='b', column4=5)], 51: [Row(column1='data2', column2=51, column3='c', column4=3)], 32: [Row(column1='data3', column2=32, column3='a', column4=6)], 91: [Row(column1='data4', column2=91, column3='a', column4=9)]}
>>> t.index_by('column3')
{'b': [Row(column1='data1', column2=86, column3='b', column4=5)], 'c': [Row(column1='data2', column2=51, column3='c', column4=3)], 'a': [Row(column1='data3', column2=32, column3='a', column4=6), Row(column1='data4', column2=91, column3='a', column4=9)]}