from pyspark.sql import functions as F
# Set column to be used to get keys of the dict
# and columns to be used to compute the values of the dict
dict_key = df.columns[0]
entry_cols = df.columns[1:]
{
r[dict_key]: r.dict_entry
for r in (
df
.select(
dict_key,
F.array_remove(
F.array(*[
F.when(F.col(c) == 'Approve', F.lit(c)).otherwise('NULL')
for c in entry_cols
]),
'NULL',
).alias('dict_entry')
)
.collect()
)
}
1条答案
按热度按时间vsikbqxv1#
基于
array
和array_remove
,您可以使用如下代码:这就是结果: