How to Insert from an excel row/cell level data into a databricks table
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 11:22 AM
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 11:52 AM
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")

