typeddfs._mixins._new_methods_mixin
ο
Mixin with misc new DataFrame methods.
Module Contentsο
- class typeddfs._mixins._new_methods_mixin._NewMethodsMixinο
- cfirst(self, cols: Union[str, int, Sequence[str]]) __qualname__ ο
Returns a new DataFrame with the specified columns appearing first.
- Parameters
cols β A list of columns, or a single column or column index
- drop_cols(self, *cols: Union[str, Iterable[str]]) __qualname__ ο
Drops columns, ignoring those that are not present.
- Parameters
cols β A single column name or a list of column names
- iter_row_col(self) Generator[Tuple[Tuple[int, int], Any], None, None] ο
Iterates over
((row, col), value)
tuples. The row and column are the row and column numbers, 1-indexed.
- only(self, column: str, exclude_na: bool = False) Any ο
Returns the single unique value in a column. Raises an error if zero or more than one value is in the column.
- Parameters
column β The name of the column
exclude_na β Exclude None/pd.NA values
- rename_cols(self, **cols) __qualname__ ο
Shorthand for
.rename(columns=)
.
- set_attrs(self, **attrs) __qualname__ ο
Sets
pd.DataFrame.attrs
, returning a copy.
- sort_natural(self, column: str, *, alg: Union[None, int, Set[str]] = None, reverse: bool = False) __qualname__ ο
Calls
natsorted
on a single column.- Parameters
column β The name of the (single) column to sort by
alg β Input as the
alg
argument tonatsorted
IfNone
, the βbestβ algorithm is chosen from the dtype ofcolumn
viatypeddfs.utils.Utils.guess_natsort_alg()
. Otherwise, :meth:typeddfs.utils.Utils.exact_natsort_alg` is called withUtils.exact_natsort_alg(alg)
.reverse β Reverse the sort order (e.g. βzβ before βaβ)
- sort_natural_index(self, *, alg: int = None, reverse: bool = False) __qualname__ ο
Calls natsorted on this index. Works for multi-index too.
- Parameters
alg β Input as the
alg
argument tonatsorted
IfNone
, the βbestβ algorithm is chosen from the dtype ofcolumn
viatypeddfs.utils.Utils.guess_natsort_alg()
. Otherwise, :meth:typeddfs.utils.Utils.exact_natsort_alg` is called withUtils.exact_natsort_alg(alg)
.reverse β Reverse the sort order (e.g. βzβ before βaβ)
- st(self, *array_conditions: Sequence[bool], **dict_conditions: Mapping[str, Any]) __qualname__ ο
Short for βsuch thatβ β an alternative to slicing with
.loc
.- Parameters
array_conditions β Conditions like
df["score"]<2
dict_conditions β Equality conditions, mapping column names to their values (ex
score=2
)
- Returns
A new DataFrame of the same type
- strip_control_chars(self) __qualname__ ο
Removes all control characters (Unicode group βCβ) from all string-typed columns.