Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda