foreachPartition

將該 f 函數套用到該資料框架的每個分割。

語法

foreachPartition(f: Callable[[Iterator[Row]], None])

參數

參數 類型 說明
f 函式 一個接受一個參數的函數,該參數將接收每個要處理的分割。

Examples

df = spark.createDataFrame(
    [(14, "Tom"), (23, "Alice"), (16, "Bob")], ["age", "name"])
def func(itr):
    for person in itr:
        print(person.name)

df.foreachPartition(func)