更新时间:2023-12-04 09:51:40
您可以创建一个命名函数并应用它-或应用lambda函数.无论哪种情况,都应对数据帧进行尽可能多的处理.
You can either create a named function and apply it - or apply a lambda function. In either case, do as much processing as possible withing the dataframe.
基于lambda的解决方案:
A lambda-based solution:
df['ORIG'].astype(str).str.encode('UTF-8')\
.apply(lambda x: base64.b64encode(hashlib.sha1(x).digest()))
命名函数解决方案:
def hashme(x):
return base64.b64encode(hashlib.sha1(x).digest())
df['ORIG'].astype(str).str.encode('UTF-8')\
.apply(hashme)