ExcelConnector¶
Excel source connector.
- class scamander.sources.excel_connector.ExcelConnector(config: Config, *args, **kwargs)¶
Basisklassen:
SourceSource connector that reads a single Excel worksheet into a Spark DataFrame.
Reads the worksheet with pandas (via the
openpyxlengine) and converts the result to a Spark DataFrame. Can be instantiated directly with flat keyword arguments, or via theSourcefactory (Source(config, spark=spark)) by passing aConfigwhosesource.optionsis anExcelSourceOptions.- Parameters:
file_path (str | Config) – Path to the Excel file on the platform filesystem (e.g. a DBFS path, an ABFS URI, or a local path for testing), or a validated
Configwhosesource.optionsis anExcelSourceOptions(theSourcefactory path — requiressparkas a keyword argument).sheet_name (str | int) – Name or zero-based index of the worksheet to read. Defaults to
0(the first sheet). Ignored whenfile_pathis aConfig.header (bool) – Whether the first row (after
skip_rows) contains column names. Defaults toTrue. Ignored whenfile_pathis aConfig.skip_rows (int) – Number of rows to skip before the header/data begins. Defaults to
0. Ignored whenfile_pathis aConfig.infer_schema (bool) – When
True, pandas infers column data types from the sheet contents. Defaults toTrue. Set toFalseto read all columns asSTRING. Ignored whenfile_pathis aConfig.spark (SparkSession) – Required keyword argument when
file_pathis aConfig; unused otherwise.
- Veroorzaakt:
ValueError – If
file_pathis aConfigwhosesource.optionsis not anExcelSourceOptionsinstance.
- connect() DataFrame¶
Reads the configured worksheet at
self.file_pathinto a Spark DataFrame.Reads the sheet with pandas, then converts the resulting pandas DataFrame into a Spark DataFrame via
spark.createDataFrame.- Returns:
A Spark DataFrame containing the worksheet data.
- Return type:
DataFrame