本文简要介绍
pyspark.sql.functions.zip_with
的用法。用法:
pyspark.sql.functions.zip_with(left, right, f)
使用函数将两个给定的数组按元素合并到一个数组中。如果一个数组较短,则在应用函数之前在末尾附加空值以匹配较长数组的长度。
版本 3.1.0 中的新函数。
- left:
Column
或 str 第一列或表达式的名称
- right:
Column
或 str 第二列或表达式的名称
- f:函数
二进制函数
(x1: Column, x2: Column) -> Column...
可以使用Column
的方法,在pyspark.sql.functions
和 Scala 中定义的函数UserDefinedFunctions
。不支持 PythonUserDefinedFunctions
(SPARK-27052)。
- left:
参数:
返回:
例子:
>>> df = spark.createDataFrame([(1, [1, 3, 5, 8], [0, 2, 4, 6])], ("id", "xs", "ys")) >>> df.select(zip_with("xs", "ys", lambda x, y: x ** y).alias("powers")).show(truncate=False) +---------------------------+ |powers | +---------------------------+ |[1.0, 9.0, 625.0, 262144.0]| +---------------------------+
>>> df = spark.createDataFrame([(1, ["foo", "bar"], [1, 2, 3])], ("id", "xs", "ys")) >>> df.select(zip_with("xs", "ys", lambda x, y: concat_ws("_", x, y)).alias("xs_ys")).show() +-----------------+ | xs_ys| +-----------------+ |[foo_1, bar_2, 3]| +-----------------+
相关用法
- Python pyspark create_map用法及代码示例
- Python pyspark date_add用法及代码示例
- Python pyspark DataFrame.to_latex用法及代码示例
- Python pyspark DataStreamReader.schema用法及代码示例
- Python pyspark MultiIndex.size用法及代码示例
- Python pyspark arrays_overlap用法及代码示例
- Python pyspark Series.asof用法及代码示例
- Python pyspark DataFrame.align用法及代码示例
- Python pyspark Index.is_monotonic_decreasing用法及代码示例
- Python pyspark IsotonicRegression用法及代码示例
- Python pyspark DataFrame.plot.bar用法及代码示例
- Python pyspark DataFrame.to_delta用法及代码示例
- Python pyspark element_at用法及代码示例
- Python pyspark explode用法及代码示例
- Python pyspark MultiIndex.hasnans用法及代码示例
- Python pyspark Series.to_frame用法及代码示例
- Python pyspark DataFrame.quantile用法及代码示例
- Python pyspark Column.withField用法及代码示例
- Python pyspark Index.values用法及代码示例
- Python pyspark Index.drop_duplicates用法及代码示例
- Python pyspark aggregate用法及代码示例
- Python pyspark IndexedRowMatrix.computeGramianMatrix用法及代码示例
- Python pyspark DecisionTreeClassifier用法及代码示例
- Python pyspark Index.value_counts用法及代码示例
- Python pyspark GroupBy.mean用法及代码示例
注:本文由纯净天空筛选整理自spark.apache.org大神的英文原创作品 pyspark.sql.functions.zip_with。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。