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 to natsorted If None, the β€œbest” algorithm is chosen from the dtype of column via typeddfs.utils.Utils.guess_natsort_alg(). Otherwise, :meth:typeddfs.utils.Utils.exact_natsort_alg` is called with Utils.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 to natsorted If None, the β€œbest” algorithm is chosen from the dtype of column via typeddfs.utils.Utils.guess_natsort_alg(). Otherwise, :meth:typeddfs.utils.Utils.exact_natsort_alg` is called with Utils.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.