本文簡要介紹
pyspark.pandas.Index.spark.transform
的用法。用法:
spark.transform(func: Callable[[pyspark.sql.column.Column], pyspark.sql.column.Column]) → IndexOpsLike
應用一個接受並返回 Spark 列的函數。它允許本地應用 Spark 函數和列 API,其中 Spark 列在 Series 或 Index 中內部使用。 Spark 列的輸出長度應與輸入的長度相同。
注意
它要求具有相同的輸入和輸出長度;因此,聚合 Spark 函數(例如 count)不起作用。
- func:函數
用於使用 Spark 列轉換數據的函數。
- 係列或索引
- ValueError:如果函數的輸出不是 Spark 列。
參數:
返回:
拋出:
例子:
>>> from pyspark.sql.functions import log >>> df = ps.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}, columns=["a", "b"]) >>> df a b 0 1 4 1 2 5 2 3 6
>>> df.a.spark.transform(lambda c: log(c)) 0 0.000000 1 0.693147 2 1.098612 Name: a, dtype: float64
>>> df.index.spark.transform(lambda c: c + 10) Int64Index([10, 11, 12], dtype='int64')
>>> df.a.spark.transform(lambda c: c + df.b.spark.column) 0 5 1 7 2 9 Name: a, dtype: int64
相關用法
- Python pyspark Index.shape用法及代碼示例
- Python pyspark Index.sort_values用法及代碼示例
- Python pyspark Index.symmetric_difference用法及代碼示例
- Python pyspark Index.size用法及代碼示例
- Python pyspark Index.set_names用法及代碼示例
- Python pyspark Index.shift用法及代碼示例
- Python pyspark Index.is_monotonic_decreasing用法及代碼示例
- Python pyspark Index.values用法及代碼示例
- Python pyspark Index.drop_duplicates用法及代碼示例
- Python pyspark Index.value_counts用法及代碼示例
- Python pyspark Index.map用法及代碼示例
- Python pyspark Index.equals用法及代碼示例
- Python pyspark Index.argmin用法及代碼示例
- Python pyspark Index.argmax用法及代碼示例
- Python pyspark Index.item用法及代碼示例
- Python pyspark Index.insert用法及代碼示例
- Python pyspark Index.nlevels用法及代碼示例
- Python pyspark Index.min用法及代碼示例
- Python pyspark Index.copy用法及代碼示例
- Python pyspark Index.difference用法及代碼示例
- Python pyspark Index.to_list用法及代碼示例
- Python pyspark Index.dropna用法及代碼示例
- Python pyspark Index.repeat用法及代碼示例
- Python pyspark Index.notna用法及代碼示例
- Python pyspark Index.has_duplicates用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.Index.spark.transform。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。