Package: anonym
anonymTheanonymlibrary is designed to anonymize sensitive data in Python, allowing users to work with, share, or publish their data without compromising privacy or violating data protection regulations. It uses Named Entity Recognition (NER) fromspacyto identify sensitive information in the data. Once identified, the library leverages thefakerlibrary to generate fake but realistic replacements. Depending on the type of sensitive information (like names, addresses, dates), corresponding faker methods are used, ensuring the anonymized data maintains a similar structure and format to the original, making it suitable for further data analysis or testing.Theanonymalgorithm is designed to anonymize data in a DataFrame. It works by replacing real data with fake data, while maintaining the structure and format of the original data. Here's a step-by-step explanation of how it works:1. Initialization: The anonym class is initialized with a language parameter (default is 'dutch') and a verbosity level (default is 'info'). The language parameter is used to load the appropriate language model for named entity recognition (NER), and the verbosity level sets the logger's verbosity.2. Data Import: The import_data method is used to import a dataset from a given file path. The data is read into a pandas DataFrame.3. Data Anonymization: The anonymize method is the core of the algorithm. It takes a DataFrame and optional parameters for specifying columns to fake or not to fake, and a NER blacklist. The method works as follows:4. It calls the extract_entities functionto extract all entities from the DataFrame. This function uses thespacylibrary's NER capabilities to identify entities in the data. If a column is specified in the fakeit parameter, the entities in that column are replaced with the specified fake replacement. If a column is specified in the do_not_fake parameter, it is left untouched. Otherwise, NER is performed on each row of the column.5. The generate_fake_labels functionis then called to generate fake labels for the extracted entities. This function uses thefakerlibrary to generate fake data that matches the type of the original data (e.g., names, companies, dates, cities, etc.).6. The replace_label_with_fake functionis then used to replace the original entities in the DataFrame with the generated fake labels.7. Data Export: The to_csv method is used to write the anonymized DataFrame to a CSV file.8. Example Data Import: The import_example method is used to import example datasets from a GitHub source or a specified URL.Start
  |
  v
Initialize `anonym` class
  |
  v
Import data using `import_data` method
  |
  v
Anonymize data using `anonymize` method
  |         |
  |         v
  |     Extract entities using `extract_entities` function
  |         |
  |         v
  |     Generate fake labels using `generate_fake_labels` function
  |         |
  |         v
  |     Replace original labels with fake ones using `replace_label_with_fake` function
  v
Export anonymized data using `to_csv` method
  |
  v
EndThe algorithm also includes several utility functions for text cleaning, preprocessing, filtering values, checking thespacymodel, and setting the logger. The main function at the end of the script demonstrates how to use the anonym class to import an example dataset, anonymize it, and plot the results.Documentationanonym documentation pages (Sphinx)ContentsInstallationContributeCitationMaintainersLicenseInstallationInstall anonym from PyPI (recommended). anonym is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows.A new environment can be created as following:condacreate-nenv_anonympython=3.10
condaactivateenv_anonympipinstallanonym# normal installpipinstall--upgradeanonym# or update if neededAlternatively, you can install from the GitHub source:# Directly install from github sourcepipinstall-egit://gitlab.com/datainnovatielab/public/anonym.git@0.1.0#egg=master
pipinstallgit+https://gitlab.com/datainnovatielab/public/anonym#egg=master
pipinstallgit+https://gitlab.com/datainnovatielab/public/anonym# By cloninggitclonehttps://gitlab.com/datainnovatielab/public/anonym.gitcdanonym
pipinstall-U.Import anonym packageimportanonymasanonymExample:# Example 2# Load libraryfromanonymimportanonym# Initializemodel=anonym(language='english',verbose='info')# Import example data setdf=model.import_example('titanic')# Anonimyze the data setdf_fake=model.anonymize(df)Referenceshttps://gitlab.com/datainnovatielab/public/anonymCitationPlease cite in your publications if this is useful for your research (see citation).ContributeAll kinds of contributions are welcome!LicenceSeeLICENSEfor details.