tabsdata.tableframe.selectors.by_name#
- by_name(*names: str | Collection[str], require_all: bool = True) SelectorProxy [source]#
Select all columns whose names match any given names.
- Parameters:
names – One or more column names to include.
require_all – If True, raises an error if any name is missing.
Example
>>> import tabsdata.tableframe as td_tf >>> >>> tf = td_tf.TableFrame({ ... "Id": [10, 11, 12, 13, 14, 15, 16, 17], ... "Name": ["Anna", "Ben", "Cara", "Dean", "Ella", "Finn", "Gina", "Hugo"], ... "Country": ["US", "UK", "FR", "DE", "IT", "ES", "NL", "SE"], ... "Score": [91.0, 84.5, 88.0, 90.5, 86.0, 87.0, 82.5, 89.5] ... })
Original: ┌──────┬────────┬─────────┬───────┐ │ Id ┆ Name ┆ Country ┆ Score │ │ — ┆ — ┆ — ┆ — │ │ i64 ┆ str ┆ str ┆ f64 │ ╞══════╪════════╪═════════╪═══════╡ │ 10 ┆ “Anna” ┆ “US” ┆ 91.0 │ │ 11 ┆ “Ben” ┆ “UK” ┆ 84.5 │ │ 12 ┆ “Cara” ┆ “FR” ┆ 88.0 │ │ 13 ┆ “Dean” ┆ “DE” ┆ 90.5 │ │ 14 ┆ “Ella” ┆ “IT” ┆ 86.0 │ │ 15 ┆ “Finn” ┆ “ES” ┆ 87.0 │ │ 16 ┆ “Gina” ┆ “NL” ┆ 82.5 │ │ 17 ┆ “Hugo” ┆ “SE” ┆ 89.5 │ └──────┴────────┴─────────┴───────┘
>>> tf.select(td_tf.selectors.by_name("Name", "Score"))
Selected: ┌────────┬───────┐ │ Name ┆ Score │ │ — ┆ — │ │ str ┆ f64 │ ╞════════╪═══════╡ │ “Anna” ┆ 91.0 │ │ “Ben” ┆ 84.5 │ │ “Cara” ┆ 88.0 │ │ “Dean” ┆ 90.5 │ │ “Ella” ┆ 86.0 │ │ “Finn” ┆ 87.0 │ │ “Gina” ┆ 82.5 │ │ “Hugo” ┆ 89.5 │ └────────┴───────┘