diff --git a/src/safeds/data/tabular/containers/_column.py b/src/safeds/data/tabular/containers/_column.py index 2f8afbe10..9a013cbf7 100644 --- a/src/safeds/data/tabular/containers/_column.py +++ b/src/safeds/data/tabular/containers/_column.py @@ -11,7 +11,6 @@ ColumnLengthMismatchError, IndexOutOfBoundsError, MissingValuesColumnError, - NonNumericColumnError, ) from ._lazy_cell import _LazyCell @@ -224,7 +223,7 @@ def get_distinct_values( def get_value(self, index: int) -> T_co: """ - Return the column value at specified index. + Return the column value at specified index. Equivalent to the `[]` operator (indexed access). Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at -1). @@ -250,6 +249,9 @@ def get_value(self, index: int) -> T_co: >>> column = Column("test", [1, 2, 3]) >>> column.get_value(1) 2 + + >>> column[1] + 2 """ if index < -self.row_count or index >= self.row_count: raise IndexOutOfBoundsError(index) @@ -435,7 +437,7 @@ def count_if( """ Return how many values in the column satisfy the predicate. - The predicate can return one of three values: + The predicate can return one of three results: * True, if the value satisfies the predicate. * False, if the value does not satisfy the predicate. @@ -459,11 +461,6 @@ def count_if( count: The number of values in the column that satisfy the predicate. - Raises - ------ - TypeError - If the predicate does not return a boolean cell. - Examples -------- >>> from safeds.data.tabular.containers import Column diff --git a/src/safeds/data/tabular/containers/_row.py b/src/safeds/data/tabular/containers/_row.py index 3d818c010..b21aed44e 100644 --- a/src/safeds/data/tabular/containers/_row.py +++ b/src/safeds/data/tabular/containers/_row.py @@ -68,7 +68,7 @@ def schema(self) -> Schema: @abstractmethod def get_value(self, name: str) -> Cell: """ - Get the value of the specified column. + Get the value of the specified column. This is equivalent to using the `[]` operator (indexed access). Parameters ---------- @@ -84,6 +84,29 @@ def get_value(self, name: str) -> Cell: ------ ColumnNotFoundError If the column name does not exist. + + Examples + -------- + >>> from safeds.data.tabular.containers import Table + >>> table = Table({"col1": [1, 2], "col2": [3, 4]}) + >>> table.remove_rows(lambda row: row.get_value("col1") == 1) + +------+------+ + | col1 | col2 | + | --- | --- | + | i64 | i64 | + +=============+ + | 2 | 4 | + +------+------+ + + + >>> table.remove_rows(lambda row: row["col1"] == 1) + +------+------+ + | col1 | col2 | + | --- | --- | + | i64 | i64 | + +=============+ + | 2 | 4 | + +------+------+ """ @abstractmethod