如何使用 Palantir Foundry 在 Pyspark 中编写案例语句

How do I write case statements in Pyspark using Palantir Foundry

试图从 VBA 中的宏中获取 case 语句并传输到 Pyspark。我将如何在 Pyspark 中编写这样的东西?

 Select Case dMinutes
                Case 0 To 30
                    xnum = 1
                Case 31 To 60
                    xnum = 2
                Case 61 To 90
                    xnum = 3
                Case 91 To 120
                    xnum = 4
                Case Else
                    xnum = 5

下面的 PySpark 应该可以实现你想要的!

import pyspark.sql.functions as F

dataset = dataset.withColumn('xnum',
    F.when(F.col('dMinutes').between(0,30), 1)
    .when(F.col('dMinutes').between(31,60), 2)
    .when(F.col('dMinutes').between(61,90), 3)
    .when(F.col('dMinutes').between(91,120), 4)
    .otherwise(5)
)