Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

454
Views
How do I write case statements in Pyspark using Palantir Foundry

Trying to take a case statement from macros in VBA and transfer into Pyspark. How would I go about writing something like this in 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
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The following PySpark should achieve what you want!

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)
)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!