cape_privacy.pandas.transformations.rounding#
NumericRounding Objects#
class NumericRounding(base.Transformation)
Reduce the precision of a numeric Pandas Series
Round each value in the Pandas Series to the given number of digits.
Example:
s = pd.Series([1.384])
round = NumericRounding(precision=1)
round(s) # pd.Series([1.4])
Attributes:
dtypes
dtypes.Numerics - Pandas Series type.precision
int - set the number of digits.
__call__#
| __call__(x: pd.Series) -> pd.Series
Round each value in the Pandas Series
Arguments:
x
A Pandas Series - need to be a list of numeric values.
Returns:
A Pandas Series with each value rounded
DateTruncation Objects#
class DateTruncation(base.Transformation)
Reduce the precision of a date Pandas Series Truncate each date in a Pandas Series to the unit (year or month) specified by frequency.
Example:
s = pd.Series([pd.Timestamp("2018-10-15")])
trunc = DateTruncation(frequency="year")
trunc(s) # pd.Serie([pd.Timestamp("2018-01-01")])
Attributes:
frequency
string - expect to be 'year' or 'month'