tabsdata.tableframe.selectors.by_index#

by_index(*indices: int | range | Sequence[int | range]) SelectorProxy[source]#

Select columns by their position in the TableFrame.

Parameters:
  • indices – One or more integer positions or ranges. Negative indexes are

  • supported (indicating last column)

  • -1 (ranging from)

  • columns} (-{number of)

  • fail. (absolute value) than the number of columns will)

Example

>>> import tabsdata.tableframe as td_tf
>>>
>>> tf = td_tf.TableFrame({
...     "Id": [1, 2, 3, 4, 5, 6, 7, 8],
...     "Name": ["A", "B", "C", "D", "E", "F", "G", "H"],
...     "IsActive": [True, False, True, True, False, True, False, True],
...     "Score": [90.0, 85.5, 88.0, 91.0, 86.0, 87.5, 84.0, 89.5]
... })

Original: ┌──────┬──────┬──────────┬───────┐ │ Id ┆ Name ┆ IsActive ┆ Score │ │ — ┆ — ┆ — ┆ — │ │ i64 ┆ str ┆ bool ┆ f64 │ ╞══════╪══════╪══════════╪═══════╡ │ 1 ┆ “A” ┆ true ┆ 90.0 │ │ 2 ┆ “B” ┆ false ┆ 85.5 │ │ 3 ┆ “C” ┆ true ┆ 88.0 │ │ 4 ┆ “D” ┆ true ┆ 91.0 │ │ 5 ┆ “E” ┆ false ┆ 86.0 │ │ 6 ┆ “F” ┆ true ┆ 87.5 │ │ 7 ┆ “G” ┆ false ┆ 84.0 │ │ 8 ┆ “H” ┆ true ┆ 89.5 │ └──────┴──────┴──────────┴───────┘

>>> tf.select(td_tf.selectors.by_index(1, 3))

Selected: ┌──────┬───────┐ │ Name ┆ Score │ │ — ┆ — │ │ str ┆ f64 │ ╞══════╪═══════╡ │ “A” ┆ 90.0 │ │ “B” ┆ 85.5 │ │ “C” ┆ 88.0 │ │ “D” ┆ 91.0 │ │ “E” ┆ 86.0 │ │ “F” ┆ 87.5 │ │ “G” ┆ 84.0 │ │ “H” ┆ 89.5 │ └──────┴───────┘