我如何规范pyspark中的数据帧?

问题描述 投票:0回答:1

我正在尝试规范用户项目矩阵,但我想使用此公式:

(df.values-df.values.min())/(df.values.max()-df.values.min())

Dataframe like this中。

pyspark normalization standardized
1个回答
0
投票

您可以创建一个函数并在其他函数中同样重用---

def compute_function(df):
  _count = (df.values-df.values.min())/(df.values.max()-df.values.min())
  df = df.withColumn("new_column", F.lit(_count))
  return df

df = compute_function(df)
df.show()
© www.soinside.com 2019 - 2024. All rights reserved.