QueryBuilder.replace_infinity#
from tmlt.analytics import QueryBuilder
- QueryBuilder.replace_infinity(replace_with=None)#
Replaces +inf and -inf values in specified columns.
Example
>>> my_private_data.toPandas() A B X 0 a1 0.0 0.0 1 a1 NaN -inf 2 a2 2.0 inf >>> budget = PureDPBudget(float("inf")) >>> sess = Session.from_dataframe( ... privacy_budget=budget, ... source_id="my_private_data", ... dataframe=my_private_data, ... protected_change=AddOneRow(), ... ) >>> # Building a query with a replace_infinity transformation >>> query = ( ... QueryBuilder("my_private_data") ... .replace_infinity( ... replace_with={ ... "X": (-100, 100), ... }, ... ) ... .groupby(KeySet.from_dict({"A": ["a1", "a2"]})) ... .count() ... ) >>> # Answering the query with infinite privacy budget >>> answer = sess.evaluate( ... query, ... PureDPBudget(float("inf")) ... ) >>> answer.sort("A").toPandas() A count 0 a1 2 1 a2 1