1

I am using the below code to compare 2 columns in data frame. I dont want to do it in pandas. Can someone help how to compare using spark data frames?

    df1=context.spark.read.option("header",True).csv("./test/input/test/Book1.csv",) 
    df1=df1.withColumn("Curated", dataclean.clean_email(col("email")))
    df1.show()
    assert_array_almost_equal(df1['expected'], df1['Curated'],verbose=True)

1 Answer 1

1

One efficient way would be to try to identify the first difference as soon as possible. One way to achieve that is via left-anti joins:

assert(df1.join(df1, (df1['expected'] == df1['Curated']), "leftanti").first() != None)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.