FormatTransformer#

class mobgap.utils.tables.FormatTransformer[source]#

Formatting functions that can be applied to a DataFrame using apply_transformations.

These functions can be applied to individual columns or to multiple columns combined by using CustomOperation. If you want to perform styling per value, usually the built-in pandas styling functions are more appropriate.

Attributes:
value_with_metadata

Combine a value column (float) and additional metadata columns into one column.

Methods

value_with_metadata(value_col, other_columns)

Combine a value column (float) and additional metadata columns into one column.

__init__(*args, **kwargs)#
value_with_metadata(value_col: ~collections.abc.Hashable, other_columns: dict[str, ~collections.abc.Hashable], precision: int = 2, base_class: type[~mobgap.utils.tables.ValueWithMetadata] = <class 'mobgap.utils.tables.CustomFormattedValueWithMetadata'>) Series[source]#

Combine a value column (float) and additional metadata columns into one column.

Note, that the return value is not a string, but a custom object that has the expected string representation. This means that if you apply this to a pandas dataframe, you can still perform regular comparisons with the values. The comparisons are based on the value only and not the range. Don’t overuse this “magic trick”. We are just using it to still apply styles based on the value in the final dataframe.

Parameters:
df

The DataFrame containing the columns.

value_col

The name of the column containing the value. This is important, as the value is used for comparisons/sorting.

other_columns

A dictionary mapping keys to column names that contain the further metadata.

precision

numbers of decimal places to use for all values during formatting.

base_class

The base class to use for the custom object. This can be used to create custom formatters that make use of the metadata.