I have below pyspark dataframe df and I want to check the id are present in another dataframe df1 and return true and false for every row.
from pyspark.sql import SparkSession
from pyspark.sql.functions import *
import pyspark.sql.functions as F
# Create SparkSession
data=[["12345","2020-02-01"],["6789","2019-03-01"],["12345","2021-03-01"],["7890",""],["5000","2021-21-01"],["80000","1900-01-01"],["90000","2000-01-01"],["","2000-01-01"]]
df=spark.createDataFrame(data,["id","Date"])
df.show()
data=[["12345"],["6789"],["7890"],["90000"]]
df1=spark.createDataFrame(data,["id"])
df1.show()
df data frame :
| id | Date |
|---|---|
| 12345 | 2020-02-01 |
| 6789 | 2019-03-01 |
| 12345 | 2021-03-01 |
| 7890 | |
| 5000 | 2021-21-01 |
| 80000 | 1900-01-01 |
| 90000 | 2000-01-01 |
| 2000-01-01 |
df1 dataframe :
| id |
|---|
| 12345 |
| 6789 |
| 7890 |
| 90000 |
I am looking to get below output based on the comparsion from df with df1.
| id | Check |
|---|---|
| 12345 | True |
| 6789 | True |
| 12345 | True |
| 7890 | True |
| 5000 | False |
| 80000 | False |
| 90000 | True |
| False |