I have a PySpark dataframe like this:
+------+------+
| A| B|
+------+------+
| 1| 2|
| 1| 3|
| 2| 3|
| 2| 5|
+------+------+
I want to do a lookup on the table to see if a specific row exists. For example, for the test of A = 2, B = 5 the code should return True and for A = 2,B = 10 the code should return False.
I tried this:
df[(df['A'] == 1) & (df['B'] == 2)].rdd.isEmpty()
Unfortunately, this code takes a long time to execute, and since this is a lookup that will be performed many times (for different values of A and B), I would like to have a quicker method of accomplishing this task.
Other solutions that I am considering are:
- Converting the PySpark dataframe to a Pandas dataframe because the row lookups are faster
- Using
.where()or.filter()though from what I have tried, I do not anticipate either being substantially faster - Using
.count()overisEmpty()