Skip to main content
Version: Next

ts_shape.transform.calculator.numeric_calc

Classes
NameDescription
IntegerCalcProvides class methods for performing calculations on integer columns in a pandas DataFrame.

IntegerCalc​

classsource

Bases: Base

Provides class methods for performing calculations on integer columns in a pandas DataFrame.

Functions
NameDescription
scale_columnScales the integer column by the given factor.
offset_columnOffsets the integer column by the given value.
divide_columnDivides each value in the integer column by the given divisor.
subtract_columnSubtracts a given value from each element in the integer column.
calculate_with_fixed_factorsPerforms a calculation by multiplying with a factor and then adding an additional factor.
mod_columnPerforms a modulus operation on the integer column with a specified value.
power_columnRaises each value in the integer column to the power of a specified value.

scale_column​

classmethodsource
scale_column(
dataframe: pd.DataFrame,
value_column: str = "value_integer",
factor: float = 1,
) -> pd.DataFrame

Scales the integer column by the given factor.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame to perform the operation on.required
value_columnstrThe column to apply the scaling to.'value_integer'
factorfloatThe scaling factor.1
Returns
TypeDescription
DataFramepd.DataFrame: The DataFrame with the scaled column.

offset_column​

classmethodsource
offset_column(
dataframe: pd.DataFrame,
value_column: str = "value_integer",
offset_value: float = 0,
) -> pd.DataFrame

Offsets the integer column by the given value.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame to perform the operation on.required
value_columnstrThe column to apply the offset to.'value_integer'
offset_valuefloatThe value to add (positive) or subtract (negative) from each element in the column.0
Returns
TypeDescription
DataFramepd.DataFrame: The DataFrame with the offset column.

divide_column​

classmethodsource
divide_column(
dataframe: pd.DataFrame,
value_column: str = "value_integer",
divisor: float = 1,
) -> pd.DataFrame

Divides each value in the integer column by the given divisor.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame to perform the operation on.required
value_columnstrThe column to apply the division to.'value_integer'
divisorfloatThe value by which to divide each element.1
Returns
TypeDescription
DataFramepd.DataFrame: The DataFrame with the divided column.
Raises
TypeDescription
ValueErrorIf divisor is zero.

subtract_column​

classmethodsource
subtract_column(
dataframe: pd.DataFrame,
value_column: str = "value_integer",
subtract_value: float = 0,
) -> pd.DataFrame

Subtracts a given value from each element in the integer column.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame to perform the operation on.required
value_columnstrThe column to apply the subtraction to.'value_integer'
subtract_valuefloatThe value to subtract from each element.0
Returns
TypeDescription
DataFramepd.DataFrame: The DataFrame with the subtracted column.

calculate_with_fixed_factors​

classmethodsource
calculate_with_fixed_factors(
dataframe: pd.DataFrame,
value_column: str = "value_integer",
multiply_factor: float = 1,
add_factor: float = 0,
) -> pd.DataFrame

Performs a calculation by multiplying with a factor and then adding an additional factor.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame to perform the operation on.required
value_columnstrThe column to apply the calculations to.'value_integer'
multiply_factorfloatThe factor to multiply each value by. Defaults to 1 (no scaling).1
add_factorfloatThe value to add after multiplication. Defaults to 0 (no offset).0
Returns
TypeDescription
DataFramepd.DataFrame: The DataFrame after applying the calculations.

mod_column​

classmethodsource
mod_column(
dataframe: pd.DataFrame,
value_column: str = "value_integer",
mod_value: int = 1,
) -> pd.DataFrame

Performs a modulus operation on the integer column with a specified value.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame to perform the operation on.required
value_columnstrThe column to apply the modulus operation to.'value_integer'
mod_valueintThe value to perform the modulus operation with.1
Returns
TypeDescription
DataFramepd.DataFrame: The DataFrame with the modulus operation applied.
Raises
TypeDescription
ValueErrorIf mod_value is zero.

power_column​

classmethodsource
power_column(
dataframe: pd.DataFrame,
value_column: str = "value_integer",
power_value: float = 1,
) -> pd.DataFrame

Raises each value in the integer column to the power of a specified value.

An integer column stays integer only when the result is exact: a non-negative whole exponent whose results all fit in int64. A negative or fractional exponent, or a result beyond int64 (e.g. 10 ** 64), gives float64 values (numpy.float_power) instead of wrapped-around integers or an error: [2, 3, 10] ** -1 is [0.5, 0.333..., 0.1]. (A nullable Int64 column becomes Float64, a pyarrow integer column double[pyarrow].) Other columns use values ** power_value.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame to perform the operation on.required
value_columnstrThe column to apply the power operation to.'value_integer'
power_valuefloatThe exponent to raise each element to.1
Returns
TypeDescription
DataFramepd.DataFrame: The DataFrame with the power operation applied.