how to access the rows and able to move back and forth in spark dataframes sing scala : I am trying to solve following problem: 

input dataframe : 

+------+------+------------+
|emp   |Group |Spouse      |
+------+------+------------+
|John  |L1    |Dana        |
|Mary  |L1    |Rick        |
|***Harry*** |L3    |Dana        |
|Linda |L3    |***Harry***       |
|Jim   |L3    |Mary        |
+------+------+------------+

Logic: The spouse of an employee must not belong to the same group as the employee(must remove those spouse's row from the list)

output dataframe:

+------+------+------------+
|Emp   |Group |Spouse      |
+------+------+------------+
|John  |L1    |Dana        |
|Mary  |L1    |Rick        |
|Linda |L3    |Harry       |
|Jim   |L3    |Mary        |
+------+------+------------+

Would anyone please help me in resolving this?