From 717adc1226e5267af2774a55c2194c14f94aabd1 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 15:31:57 -0500 Subject: [PATCH] Update column-selection.qmd --- docs/get-started/column-selection.qmd | 42 ++++++++++++--------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/docs/get-started/column-selection.qmd b/docs/get-started/column-selection.qmd index 640cd7114..72c9a048d 100644 --- a/docs/get-started/column-selection.qmd +++ b/docs/get-started/column-selection.qmd @@ -4,16 +4,13 @@ jupyter: python3 html-table-processing: none --- -The `columns=` argument for functions like `.tab_spanner()` and `.cols_move()` can accept a range of arguments. -In the above examples, we just passed a list of strings with the exact column names. +The `columns=` argument for methods like [`tab_spanner()`](`great_tables.GT.tab_spanner`) and [`cols_move()`](`great_tables.GT.cols_move`) can accept a range of arguments. In the previous examples, we just passed a list of strings with the exact column names. However, we can specify columns using any of the following: -However, we can specify columns using any of the following: - -* A single string column name. -* An integer for the column's position. -* A list of strings or integers. -* A polars selector. -* A function that takes a string and returns True or False. +* a single string column name. +* an integer for the column's position. +* a list of strings or integers. +* a **Polars** selector. +* a function that takes a string and returns `True` or `False`. ```{python} from great_tables import GT @@ -26,34 +23,31 @@ gt_ex ## String and integer selectors -Use a list of strings or integers to select columns by name or position, respectively. +We can use a list of strings or integers to select columns by name or position, respectively. ```{python} -gt_ex.cols_move_to_start(["date", 1, -1]) +gt_ex.cols_move_to_start(columns=["date", 1, -1]) ``` Note the code above moved the following columns: * The string `"date"` matched the column of the same name. -* The integer `1` matched the second column (similar to list indexing). +* The integer `1` matched the second column (this is similar to list indexing). * The integer `-1` matched the last column. -Moreover, the order of the list defines the order of selected columns. -In this case, `"data"` was the first entry, so it's the very first column in the new table. +Moreover, the order of the list defines the order of selected columns. In this case, `"data"` was the first entry, so it's the very first column in the new table. -## Function selectors +## Using function selectors -A function can be used to select columns. It should take a string and returns True or False. +A function can be used to select columns. It should take a string and returns `True` or `False`. ```{python} -gt_ex.cols_move_to_start(lambda x: "c" in x) +gt_ex.cols_move_to_start(columns=lambda x: "c" in x) ``` -## Polars selectors - -When using a polars DataFrame, you can select columns using [polars selectors](https://pola-rs.github.io/polars/py-polars/html/reference/selectors.html). +## **Polars** selectors -The example below uses polars selectors to move all columns that start with `"c"` or `"f"` to the start of the table. +When using a **Polars** DataFrame, you can select columns using [**Polars** selectors](https://pola-rs.github.io/polars/py-polars/html/reference/selectors.html). The example below uses **Polars** selectors to move all columns that start with `"c"` or `"f"` to the start of the table. ```{python} import polars as pl @@ -61,15 +55,15 @@ import polars.selectors as cs pl_df = pl.from_pandas(exibble) -GT(pl_df).cols_move_to_start(cs.starts_with("c") | cs.starts_with("f")) +GT(pl_df).cols_move_to_start(columns=cs.starts_with("c") | cs.starts_with("f")) ``` -In general, selection should match the behaviors of the polars `DataFrame.select()` method. +In general, selection should match the behaviors of the **Polars** `DataFrame.select()` method. ```{python} pl_df.select(cs.starts_with("c") | cs.starts_with("f")).columns ``` -See the [Selectors page in the polars docs](https://pola-rs.github.io/polars/py-polars/html/reference/selectors.html) for more information. +See the [Selectors page in the polars docs](https://pola-rs.github.io/polars/py-polars/html/reference/selectors.html) for more information on this.