CryptPandas allows you to easily encrypt and decrypt pandas dataframe, regardless of their content.
You can install with pip as:
pip install cryptpandas
Encrypting and decrypting your pandas dataframe is easy:
import pandas as pd
import cryptpandas as crp
df = pd.DataFrame({'A': [1, 2, 3],
'B': ['one', 'one', 'four']})
crp.to_encrypted(df, password='mypassword123', path='file.crypt')
decrypted_df = crp.read_encrypted(path='file.crypt', password='mypassword123')
print((df == decrypted_df).all().all())
By default CryptPandas uses PBKDF2 with a default salt. This allows anyone with your chosen password or passphrase to decrypt the content of your encrypted dataframe.
For an additional layer of security you can generate your own salt with cryptpandas.make_salt
.
For example:
import pandas as pd, cryptpandas as crp
df = pd.DataFrame({'A': [1, 2, 3],
'B': ['one', 'one', 'four']})
my_salt = crp.make_salt()
crp.to_encrypted(df, password='mypassword123', path='file.crypt', salt=my_salt)
decrypted_df = crp.read_encrypted(path='file.crypt', password='mypassword123', salt=my_salt)
Now it is possible to decrypt the encrypted dataframe only if in possession of both the salt and the password.
pandas
cryptography
pyarrow
Luca Mingarelli, 2020