У меня есть кадр данных, как показано ниже в pyspark
.
+-----+---+---+----+
|tests|val|asd|cnty|
+-----+---+---+----+
|test1| Y| 1|null|
|test2| N| 2| UK|
| null| Y| 1| UK|
|test1| N| 2|null|
| null| N| 3|null|
|test3| N| 4| AUS|
|test4| Y| 5|null|
+-----+---+---+----+
Я хочу обновить столбец val
, когда для любого данного tests
будет val Y
, тогда все val's
этого конкретного tests
должны быть обновлены до Y
.если нет то какие ценности они имеют.Я хочу исключить записи, в которых столбец tests
имеет значения null
.
Я сделал, как показано ниже
from pyspark.sql import Window
import pyspark.sql.functions as f
df1 = df.select('tests', f.max('val').over(Window.partitionBy('tests')).alias('val'), 'asd', 'cnty')
Я получаю результат, как показано ниже
+-----+---+---+----+
|tests|val|asd|cnty|
+-----+---+---+----+
|test1| Y| 1|null|
|test1| Y| 2|null|
|test2| N| 2| UK|
|test3| N| 4| AUS|
|test4| Y| 5|null|
| null| Y| 1| UK|
| null| Y| 3|null|
+-----+---+---+----+
Я хочу, чтобы результат был как ниже
+-----+---+---+----+
|tests|val|asd|cnty|
+-----+---+---+----+
|test1| Y| 1|null|
|test1| Y| 2|null|
|test2| N| 2| UK|
|test3| N| 4| AUS|
|test4| Y| 5|null|
| null| Y| 1| UK|
| null| N| 3|null|
+-----+---+---+----+