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



试图从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)
)

相关内容

  • 没有找到相关文章

最新更新