代码之家  ›  专栏  ›  技术社区  ›  Galuoises

PySpark的RobustScaler和熊猫

  •  0
  • Galuoises  · 技术社区  · 6 年前

    def robscal(sdf, col_name):
        lst_quantile = sdf.select(col_name).toPandas().quantile([0.25, 0.5, 0.75]).values.tolist()
        q1, q2, q3 = [y for x in lst_quantile for y in x]
        return sdf.withColumn(col_name, (sf.col(col_name)-q2)/(q3-q1))
    

    我想用熊猫udf来避免这种转换,但我不知道怎么做。你能帮帮我吗?

    0 回复  |  直到 6 年前
    推荐文章