How to implement the where not exists pattern in scala?

tarente
New Contributor III

I have a dataframe with the following columns:

  • Key1
  • Key2
  • Y_N_Col
  • Col1
  • Col2

For the key tuple (Key1, Key2), I have rows with Y_N_Col = "Y" and Y_N_Col = "N".

I need a new dataframe with all rows with Y_N_Col = "Y" (regardless of the key tuple), plus all Y_N_Col = "N" for which there are no Y_N_Col = "Y" for the same key tuple.

The dataframe is already calculated in a Scala notebook.

Thanks in advance,

Tiago R.