我嘗試將month、weak和dayofyear列轉換為回圈特征(sin,cos),我的python代碼是這樣的:
def encode(data, col, max_val):
data[col '_sin'] = np.sin(2 * np.pi * data[col]/max_val)
data[col '_cos'] = np.cos(2 * np.pi * data[col]/max_val)
return data
pyspark中的代碼是這樣的:
df = df.withColumn('month_sin',np.sin(2 * np.pi * df['month']/12))
我收到此錯誤:
TypeError: loop of ufunc does not support argument 0 of type Column which has no callable sin method
月份的列型別是整數,我將它轉換為浮點和雙精度,但沒有幫助。
注意:該列沒有零 (0) 值。
uj5u.com熱心網友回復:
你必須使用 PySparksin和 pythonmath.pi而不是np
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/437349.html
上一篇:你將如何在postgresql中創建一個十進制序列?
下一篇:Pyspark中的滯后移位功能
