- Write Excel with Python Pandas – Python Tutorial (pythonbasics.org)
- pyspark.pandas.DataFrame.to_excel — PySpark 3.3.2 documentation (apache.org)
- How to work with files on Azure Databricks – Azure Databricks | Microsoft Learn
สร้าง pandas DataFrame
%python
import pandas as pd
import openpyxl
df = pd.DataFrame([[11, 21, 31], [12, 22, 32], [31, 32, 33]],
index=['one', 'two', 'three'], columns=['a', 'b', 'c'])
print(df)
# a b c
# one 11 21 31
# two 12 22 32
# three 31 32 33
print(type(df))
# <class 'pandas.core.frame.DataFrame'>
เขียน pandas DataFrame ลงไฟล์
%python
path = '/tmp/'
filename = f'{path}output1.xlsx'
print(filename)
with pd.ExcelWriter(filename) as writer:
df.to_excel(writer, sheet_name='Sheet_name_1')