大家早上好。
我想将我的社会保障号码转换成MD5哈希十六进制数。结果应该是每个社会保障号码的唯一MD5哈希十六进制数。
我的数据格式如下:
ob = onboard[['regions','lname','ssno']][:10]
ob
regions lname ssno
0 Northern Region (R1) Banderas 123456789
1 Northern Region (R1) Garfield 234567891
2 Northern Region (R1) Pacino 345678912
3 Northern Region (R1) Baldwin 456789123
4 Northern Region (R1) Brody 567891234
5 Northern Region (R1) Johnson 6789123456
6 Northern Region (R1) Guinness 7890123456
7 Northern Region (R1) Hopkins 891234567
8 Northern Region (R1) Paul 891234567
9 Northern Region (R1) Arkin 987654321
我用以下代码尝试使用hashlib
:
import hashlib
ob['md5'] = hashlib.md5(['ssno'])
这给了我一个错误,说它必须是字符串而不是列表。所以我尝试了以下方法:
ob['md5'] = hashlib.md5('ssno').hexdigest()
regions lname ssno md5
0 Northern Region (R1) Banderas 123456789 a1b3ec3d8a026d392ad551701ad7881e
1 Northern Region (R1) Garfield 234567891 a1b3ec3d8a026d392ad551701ad7881e
2 Northern Region (R1) Pacino 345678912 a1b3ec3d8a026d392ad551701ad7881e
3 Northern Region (R1) Baldwin 456789123 a1b3ec3d8a026d392ad551701ad7881e
4 Northern Region (R1) Brody 567891234 a1b3ec3d8a026d392ad551701ad7881e
5 Northern Region (R1) Johnson 678912345 a1b3ec3d8a026d392ad551701ad7881e
6 Northern Region (R1) Johnson 789123456 a1b3ec3d8a026d392ad551701ad7881e
7 Northern Region (R1) Guiness 891234567 a1b3ec3d8a026d392ad551701ad7881e
8 Northern Region (R1) Hopkins 912345678 a1b3ec3d8a026d392ad551701ad7881e
9 Northern Region (R1) Paul 159753456 a1b3ec3d8a026d392ad551701ad7881e
这跟我需要的很接近,不过所有的十六进制数输出都一样,无论社会安全号码是否不同。我想要获得每个社会安全号码唯一的十六进制数。有什么建议吗?