# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# +
from tabular_anonymizer import DataFrameAnonymizer
import pandas as pd

#
# K-Anonymity example
#

# Load example data from csv file in current folder
file1 = "./adult.csv"
df = pd.read_csv(file1, sep=",", index_col=0)

# Sanitize data, fix index
df.reset_index()
df.index = range(len(df))

# Lets anonymize just subset of data for quick results
df = df.head(1000)

# + pycharm={"name": "#%%\n"}
# Parameters setup

# Declare Sensitive attributes you don't want to alter
sensitive_columns = ['label']

# Declare average columns.
# This leaves mean values of combined rows instead of interval-values after anonymization
avg_columns = ['capital-gain', 'capital-loss']

# Declare K
k = 10

# + pycharm={"name": "#%%\n"}
# Init dataframe anonymizer
p = DataFrameAnonymizer(sensitive_columns, avg_columns=avg_columns)

# Anonymize dataframe
df_anonymized = p.anonymize_k_anonymity(df, k=k)
df_anonymized.head(20)

# + pycharm={"name": "#%%\n"}


StarcoderdataJupyterScriptsDedupFiltered