Suppose you have a pyspark dataframe with two columns, id and val.
You want to filter rows, where a single id-window has at least one val entry with a certain value.
E.g. if we want to get rows, where an id-window has at least one 5 value in the val column:
# Input:
df = spark.createDataFrame(
[(1, '0'),
(1, '5'),
(2, '2'),
(2, '5'),
(2, '5'),
(3, '1'),
(3, '0'),],
['id', 'val']
)
# Desired output:
+---+----+
| id| val|
+---+----+
| 1| 0|
| 1| 5|
| 2| 2|
| 2| 5|
| 2| 5|
+---+----+
I thought about using the window function somehow?