Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Realistic data corruption (based on GeCo).

Project description

Corruptor

PyPI PyPI - License PyPI - Python Version

Want to realistically corrupt your (textual) data? Use Corruptor!

pip install corruptor

The supported type of corruptions:

  • OCR variation
  • Phonetic variation
  • Typing error
  • Edit (insert, delete, replace, swap)

Getting started

There are three different classes that can be used.

BasicCorruptor

The basic corruptor provides methods for each type of corruption, using default configuration.

>>> from corruptor import BasicCorruptor
>>> basic = BasicCorruptor()
>>> basic.ocr('johnson')
'johnst0n'
>>> basic.phonetic('johnson')
'johnzon'
>>> basic.typo('johnson')
'johhson'
>>> basic.insert('johnson')
'johnsson'
>>> basic.delete('johnson')
'jhnson'
>>> basic.replace('johnson')
'johnsin'
>>> basic.swap('johnson')
'johnsno'

ProbabilisticCorruptor

This class selects the type of corruption at random, based on provided weights.

>>> from corruptor import ProbabilisticCorruptor
>>> prob = ProbabilisticCorruptor({'none': 0.33, 'phonetic': 0.33, 'typo': 0.33})
>>> prob.corrupt('conner')
'conner'
>>> prob.corrupt('conner')
'conneah'
>>> prob.corrupt('conner')
'conber'

DataFrameCorruptor

In short, the DataFrame corruptor randomly corrupts n rows of a pandas DataFrame.

>>> import pandas as pd
>>> from corruptor import DataFrameCorruptor
>>> df = pd.DataFrame({'firstname': ['frank', 'john'], 'lastname': ['johnson', 'conner']})
>>> dfc = DataFrameCorruptor({'firstname': (0.5, prob), 'lastname': (0.5, prob)})
>>> dfc.corrupt(df, n=2)
  firstname lastname
0     frahk  johnson
1      john   conber

Project details


Release history Release notifications

This version
History Node

0.3.1

History Node

0.3.0

History Node

0.2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
corruptor-0.3.1-py2.py3-none-any.whl (28.4 kB) Copy SHA256 hash SHA256 Wheel py2.py3 May 25, 2018
corruptor-0.3.1.tar.gz (27.3 kB) Copy SHA256 hash SHA256 Source None May 25, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page