如何读取包含 Excel 公式的 Excel 文件以通过 PySpark lib com.crealytics.spark.excel 计算值

问题描述 投票:0回答:1

我有一个 Excel 文件,例如:

它具有使用 Excel 公式计算每个值的列

我尝试使用以下方式读取此文件:

input_MonthGroup_df = spark.read.format("com.crealytics.spark.excel") \
    .option("header", "true") \
    .option('inferSchema','true')\
    .load(MonthGroup_file_path)

O/P 错了:

azure apache-spark pyspark apache-spark-sql
1个回答
0
投票

您可以使用下面的代码来读取制定的Excel文件:

import pandas as pd
import openpyxl
from pyspark.sql.types import StructType, StructField, DateType

df = pd.read_excel(<filePath>, engine="openpyxl")
schema = StructType([StructField("Month", DateType(), True), StructField("12 Month Lookback", DateType(), True)])
sdf = spark.createDataFrame(df, schema=schema)
sdf.show()

这将读取文件,如下所示:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.