Pandas accessor for replacing, removing, or encrypting a DataFrame or Series that contains Personally Identifiable Information (PII) or Protected Health Information (PHI)
Project description
Clean Pandas
Pandas accessor for replacing, removing, or encrypting a DataFrame or Series that contains Personally Identifiable Information (PII) or Protected Health Information (PHI)
Dependencies
Installation
pip install clean_pandas
Clean Type Options
encrypt
(default) - Utilizes the cryptography library and uses Fernet (symmetric encryption)- NOTE: You must use the
serialize_encryption_key
before ending your REPL or program in order to decrypt
- NOTE: You must use the
faker
- Utilizes the Faker library and requires user denote the Faker "fake" to usescrubadub
- Utilizes the Scrubadub library to detect and replace PIItruncate
- Truncates the data by casting to a string, if possible, and recast to original type if possible. ReturnsNone
if truncation is longer than the value length. Returns the string value if cannot be cast back to original type
Basic Usage
>>> from clean_pandas import CleanPandas
>>> import pandas as pd
>>> test_df = pd.DataFrame({"first_name": ["Charles", "Stephen"],
"last_name": ["Darwin", "Hawking"],
"ssn": ["555-55-5555", "123-45-6789"]})
>>> result_df, encryption_key, dtype_dict = test_df.clean_pandas.encrypt('ssn')
>>> result_df['ssn']
0 b'gAAAAABbextrtJcQfOt37HK7pEISBokuh9ndWwGhvZpv...
1 b'gAAAAABbextrHo7qFr6DIZ0FlvVyO73HOmOYujKsv6vS...
Name: ssn, dtype: object
>>> test_df.clean_pandas.fake_it('last_name', faker_type='first_name')['last_name']
0 Joshua
1 Michael
Name: last_name, dtype: object
>>> test_df.clean_pandas.scrub_it('ssn')['ssn']
0 {{SSN}}
1 {{SSN}}
Name: ssn, dtype: object
>>> test_df.clean_pandas.truncate('ssn', trunc_length=7, trunc_from_end=False)['ssn']
0 5555
1 6789
Name: ssn, dtype: object
# Decrypt a series
>>> result_df, encryption_key, dtype_dict = test_df.clean_pandas.encrypt('ssn') # encrypt
>>> test_df.some_id
0 b'gAAAAABblA1SIGqKbTC97RjEibmB4FBHnXqKVocvFMg4...
1 b'gAAAAABblA1Sc_StggFPj0zmQLUVo0ADqHQtljUEGcr0...
Name: some_id, dtype: object
# Automatically casts back to original dtype with optional dtype argument
>>> result_df.clean_pandas.decrypt('some_id', encryption_key, dtype_dict)['some_id']
0 1
1 2
Name: some_id, dtype: int64
License
MIT License
Copyright (c) 2018 Aaron Burgess
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file clean_pandas-1.0.0.tar.gz
.
File metadata
- Download URL: clean_pandas-1.0.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbb0d120f1a2c110eadbbdfa0a45b49a2e68992cf5d34327bfe1af38b9277fb2 |
|
MD5 | cba7c4fd9bc64ceb144c8f3074cfea09 |
|
BLAKE2b-256 | 0f032263e62fa5088d215c6078b53667c0496e4671925bffa4d806204b432ac0 |
File details
Details for the file clean_pandas-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: clean_pandas-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3443d26f1bd93640ab78c43d34717b6f55ceb799d23df4e964bb815f018d819e |
|
MD5 | 82ebb37e78d722aa79b8c13148b2da1f |
|
BLAKE2b-256 | 0525ef2a686f5beb8d1fa83e24beafcc6e77a26b8d94d6ead172c306b672650c |