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

99
Views
Case statement issue in Pyspark

I'm currently writing this code in Pyspark but I'm getting errors and I know it's wrong but I'm not sure how to fix it. I'm trying to say that if 1 then I want to use a certain column with the value inside of it, if 2 this other column with the value inside of it and so on.

    ABC_SCHED = ABC_SCHED.withColumn("ABC123",
    F.when(F.col("MINS_TRA" == "1"), ABC_SCHED.T1_0to30)
    .when(F.col("MINS_TRA" == "2"), ABC_SCHED.T2_31to60)
    .when(F.col("MINS_TRA" == "3"), ABC_SCHED.T3_61to90)
    .when(F.col("MINS_TRA" == "4"), ABC_SCHED.T4_91to120)
    .when(F.col("MINS_TRA" == "5"), ABC_SCHED.T4_120ORMORE)
    .otherwise(F.lit(None))
    )

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I found the answer! I just had parentheses in the wrong places

    ABC_SCHED = ABC_SCHED.withColumn("ABC123",
    F.when((F.col("MINS_TRA") == "1"), ABC_SCHED.T1_0to30)
    .when((F.col("MINS_TRA") == "2"), ABC_SCHED.T2_31to60)
    .when((F.col("MINS_TRA") == "3"), ABC_SCHED.T3_61to90)
    .when((F.col("MINS_TRA") == "4"), ABC_SCHED.T4_91to120)
    .when((F.col("MINS_TRA") == "5"), ABC_SCHED.T5_120ORMORE)
    .otherwise(F.lit(None))
    )
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!