Python Pandas MD5 值不在索引中
Python Pandas MD5 Value not in index
我正在尝试在导入的 csv 文件中修改和添加一些列。
我的想法是我想要 2 个额外的列,一个是电子邮件地址的 MD5 值,一个是电子邮件的 SHA256 值。
+----+-----------+---------+
| id | email | status |
| 1 | 1@foo.com | ERROR |
| 2 | 2@foo.com | SUCCESS |
| 3 | 3@bar.com | SUCCESS |
+----+-----------+---------+
我试过
df['email_md5'] = md5_crypt.hash(df[df.email])
这给我一个错误提示:
KeyError: "['1@foo.com'
'2@foo.com'\n '3@bar.com'] not
in index"
我在另一个 post 中看到它建议使用 reindex
,但我无法使用它。
如果您要查找 md5_crypt.hash
,则必须使用 pd.apply()
-
将 md5_crypt 模块的散列函数应用于每封电子邮件
from passlib.hash import md5_crypt
df['email_md5'] = df['email'].apply(md5_crypt.hash)
输出
id email status email_md5
1 1@foo.com ERROR 11 lHP8aPeET4jqc/qir9yFszVikeSM0
2 2@foo.com SUCCESS 11 jyOWkcrw$I8iStC3up3cwLLLBwnT5S/
3 3@bar.com SUCCESS 11 oDfnN5UH$/2N6YljJRMfDxY2gXLYCA/
我正在尝试在导入的 csv 文件中修改和添加一些列。 我的想法是我想要 2 个额外的列,一个是电子邮件地址的 MD5 值,一个是电子邮件的 SHA256 值。
+----+-----------+---------+
| id | email | status |
| 1 | 1@foo.com | ERROR |
| 2 | 2@foo.com | SUCCESS |
| 3 | 3@bar.com | SUCCESS |
+----+-----------+---------+
我试过
df['email_md5'] = md5_crypt.hash(df[df.email])
这给我一个错误提示:
KeyError: "['1@foo.com' '2@foo.com'\n '3@bar.com'] not in index"
我在另一个 post reindex
,但我无法使用它。
如果您要查找 md5_crypt.hash
,则必须使用 pd.apply()
-
from passlib.hash import md5_crypt
df['email_md5'] = df['email'].apply(md5_crypt.hash)
输出
id email status email_md5
1 1@foo.com ERROR 11 lHP8aPeET4jqc/qir9yFszVikeSM0
2 2@foo.com SUCCESS 11 jyOWkcrw$I8iStC3up3cwLLLBwnT5S/
3 3@bar.com SUCCESS 11 oDfnN5UH$/2N6YljJRMfDxY2gXLYCA/