if statement fails when there is no value

arkiboys 9,706 Reputation points
2023-08-04T17:21:44.2866667+00:00

hello,

the if statement fails when there is no value in df_data_2
How can I correct this?

thanks

if (round(df_data_1.collect()[0][0], 3) == round(df_data_2.collect()[0][0], 3)):

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,406 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sedat SALMAN 14,160 Reputation points MVP
    2023-08-04T21:06:37.85+00:00

    you can modify the following

    df_data_1_1 = df_data_1.collect()
    df_data_2_2 = df_data_2.collect()
    
    if df_data_1_1 and df_data_2_2: 
        if round(df_data_1_collected[0][0], 3) == round(df_data_2_collected[0][0], 3):
            # code here 
            pass
        else:
            print("xxxxxxx")
    else:
        print("empty dataframe")
    
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.