I'm trying to modify and add some columns in an imported csv file. The idea is that I want 2 extra columns, one with the MD5 value of the email address, and one with the SHA256 value of the email.
+----+-----------+---------+
| id | email | status |
| 1 | 1@foo.com | ERROR |
| 2 | 2@foo.com | SUCCESS |
| 3 | 3@bar.com | SUCCESS |
+----+-----------+---------+
I have tryed with
df['email_md5'] = md5_crypt.hash(df[df.email])
This gives me an error saying:
KeyError: "['1@foo.com' '2@foo.com'\\n '3@bar.com'] not in index"
I have seen in another post Pandas KeyError: value not in index its suggested to use reindex
, but I can't get this to work.
If you are looking for md5_crypt.hash
, you will have to apply the hash function of the md5_crypt module to each of the emails using pd.apply()
-
from passlib.hash import md5_crypt
df['email_md5'] = df['email'].apply(md5_crypt.hash)
Output
id email status email_md5
1 1@foo.com ERROR 11 lHP8aPeE$5T4jqc/qir9yFszVikeSM0
2 2@foo.com SUCCESS 11 jyOWkcrw$I8iStC3up3cwLLLBwnT5S/
3 3@bar.com SUCCESS 11 oDfnN5UH$/2N6YljJRMfDxY2gXLYCA/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.