PySpark中的Proc-rank-alternative

PySpark中的Proc-rank-alternative,pyspark,sas,proc,Pyspark,Sas,Proc,我想在PySpark中转换以下SAS代码: def grouping(data): dec=pd.qcut(data['Col1','Col2','Col3','Col4'],3,labels=False) data['ranks']=dec return data RESULT =INP.apply(grouping) SAS: 我试图使用下面的PySpark代码实现上述功能,但得到的错误是“DataFrame”对象没有属性“apply” Pypark: def gr

我想在PySpark中转换以下SAS代码:

def grouping(data):
    dec=pd.qcut(data['Col1','Col2','Col3','Col4'],3,labels=False)
    data['ranks']=dec
    return data
RESULT =INP.apply(grouping)
SAS:

我试图使用下面的PySpark代码实现上述功能,但得到的错误是“DataFrame”对象没有属性“apply” Pypark:

def grouping(data):
    dec=pd.qcut(data['Col1','Col2','Col3','Col4'],3,labels=False)
    data['ranks']=dec
    return data
RESULT =INP.apply(grouping)
非常感谢您在这方面的帮助


谢谢

尝试了以下解决方案:-

RESULT = sqlContext.sql(
"""
SELECT  *,
     ntile(3) OVER (order by Col1 desc) AS R_Col1,
     ntile(3) OVER (order by Col2 desc) AS F_Col2,
     ntile(3) OVER (order by Col3 desc) AS M_Col3,
     ntile(3) OVER (order by Col4 desc) AS O_Col4
FROM INP
WHERE col=1
"""
)

那不是Pypark代码。您正在使用pandas提供的
qcut()
,pyspark不支持该功能。也就是说,还有其他方法可以实现你想要的。查看pyspark函数文档了解更多信息。你想在那里经历一段时间。