python - Python - 应该将哪种编码应用于要传递给 hashlib.sha256() 的字符串?
问题描述
首先我在 pyspark udf 中使用了这个函数,它工作正常
def encrypt_hash_col_value(column):
sha_value = hashlib.sha256(column.encode()).hexdigest()
return sha_value
spark_udf = udf(encrypt_hash_col_value, StringType())
df_hashed = df.withColumn("metric_1", spark_udf("metric_1"))
但是pandas_udf
首先我得到一个错误:
AttributeError: 'Series' object has no attribute 'encode'
我通过修改行来解决这个问题hashlib.sha256(column.str.encode()).hexdigest()
。
但现在它失败了TypeError: encode() missing 1 required positional argument: 'encoding'
。在这种情况下,应该将什么编码作为参数添加到 column.str.encode() ?
当我使用 column.str.encode("UTF-8") 时,出现此错误:TypeError: object supporting the buffer API required
解决方案
推荐阅读
- mapi - AD 中没有自动发现服务器,Outlook Redemption
- vba - 如何为 SIMPLE BLOCK 编写 DXF 代码?
- reactjs - 如何为对象提供接口
- javascript - 如何通过js文件中的ajax获取请求参数?
- laravel - Laravel 奇怪的时间错误“现在 - 6.0E+26 秒”
- mercurial - 查找在 Mercurial 中复制的文件
- reactjs - 如何在反应中设置状态c3js图形值
- python - 除非我固定版本,否则为什么 pip install 会失败?
- c# - 如何在 SOAP 服务参考 C# 中设置 WSS-Type
- html - HTML5 电子邮件验证正则表达式只有一个域