excel (DataFrameReader)

Excelファイルを読み込み、結果を DataFrame として返します。

構文

excel(path, dataAddress=None, headerRows=None, listSheets=None,
      dateFormat=None, timestampFormat=None)

パラメーター

パラメーター タイプ 説明
path str または list 1 つ以上の入力パス。
dataAddress str、省略可能 Excel ファイル内のデータのアドレス。
headerRows int または str、省略可能 ヘッダー行の数。
listSheets bool または str、省略可能 True場合は、データを読み取るのではなく、シート名の一覧を返します。
dateFormat str、省略可能 日付書式指定文字列。
timestampFormat str、省略可能 タイムスタンプの書式指定文字列。

返品

DataFrame

例示

DataFrame を Excel ファイルに書き込み、読み戻します。

import tempfile
with tempfile.TemporaryDirectory(prefix="excel") as d:
    spark.createDataFrame(
        [{"age": 100.1, "name": "Alice"}]
    ).write.mode("overwrite").option("headerRows", 1).excel(d)

    spark.read.excel(d, headerRows=1).show()
    # +-----+------------+
    # |  age|        name|
    # +-----+------------+
    # |100.1|Alice|
    # +-----+------------+