Skip to content

Instantly share code, notes, and snippets.

@koconder
Created June 18, 2023 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koconder/a646980280b1139de7cda577d3bb1307 to your computer and use it in GitHub Desktop.
Save koconder/a646980280b1139de7cda577d3bb1307 to your computer and use it in GitHub Desktop.
SHA256 a CSV file using Pandas
import pandas as pd
import hashlib
# Load the csv file into a pandas DataFrame
df = pd.read_csv('filename.csv')
# Define a function to hash a string
def hash_for_google(input):
if pd.isnull(input):
return None
input = str(input).lower().strip()
return hashlib.sha256(input.encode()).hexdigest()
# Apply the hash function to the 'Email', 'First Name', and 'Last Name' columns
df['Email'] = df['Email'].apply(hash_for_google)
df['First Name'] = df['First Name'].apply(hash_for_google)
df['Last Name'] = df['Last Name'].apply(hash_for_google)
# Save the DataFrame to a new csv file
df.to_csv('hashed_emails.csv', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment