from pyspark.sql.types import StringType
from pyspark.sql import functions as F
columns = ["ID", "A", "B", "C"]
data = [("1fe2", "2022-4-21", "2020-9-12", "2022-3-2"), ("3gef", "2021-5-22", "2019-3-4", "2022-4-2")]
df = spark.createDataFrame(data, columns)
// first concat the col name to the value
for col_name in (df.schema.fieldNames()):
if col_name != "ID":
df = df.withColumn(col_name, F.concat_ws(' ', F.col(col_name), F.lit(col_name)))
// then least() on each row
df.select(df.ID, F.least(df.A, df.B, df.C)).show()
1条答案
按热度按时间nlejzf6q1#