How to Insert from an excel row/cell level data into a databricks table

SureshRajG
Databricks Partner
 

Stefan-Koch
Databricks Partner

Hi

You can achieve that with pandas. See the following example code:

%pip install openpyxl
import pandas as pd

file_location_xls = "path/to/excel/1.xlsx"

# read the sheet with Name Financials1" into a pandas dataframe
pdf = pd.read_excel(file_location_xls, sheet_name="Financials1")

# Transform the Pandas Dataframe to a Pyspark Dataframe
df = spark.createDataFrame(pdf)

# Save Dataframe as Unity Catalog table
df.write.saveAsTable("default.bronze.excel_data")